Skip to content

Commit

Permalink
enhance: add IsMouseWheelEnabled attach property.
Browse files Browse the repository at this point in the history
  • Loading branch information
NaBian committed Mar 5, 2024
1 parent c058343 commit b0d7cc8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/Shared/HandyControl_Shared/Controls/Attach/ComboBoxAttach.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Windows;
using HandyControl.Data;

namespace HandyControl.Controls;

public class ComboBoxAttach
{
public static readonly DependencyProperty IsMouseWheelEnabledProperty = DependencyProperty.RegisterAttached(
"IsMouseWheelEnabled", typeof(bool), typeof(ComboBoxAttach), new PropertyMetadata(ValueBoxes.TrueBox, OnIsMouseWheelEnabledChanged));

private static void OnIsMouseWheelEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is not System.Windows.Controls.ComboBox comboBox)
{
return;
}

if (!(bool) e.NewValue)
{
comboBox.PreviewMouseWheel += OnComboBoxPreviewMouseWheel;
}
else
{
comboBox.PreviewMouseWheel -= OnComboBoxPreviewMouseWheel;
}

return;

static void OnComboBoxPreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs args)
{
if (sender is System.Windows.Controls.ComboBox { IsDropDownOpen: true })
{
return;
}

args.Handled = true;
}
}

public static void SetIsMouseWheelEnabled(DependencyObject element, bool value)
=> element.SetValue(IsMouseWheelEnabledProperty, ValueBoxes.BooleanBox(value));

public static bool GetIsMouseWheelEnabled(DependencyObject element)
=> (bool) element.GetValue(IsMouseWheelEnabledProperty);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\DataGridAttach.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\DropDownElement.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\EdgeElement.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\ComboBoxAttach.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\GridAttach.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\GridViewAttach.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\IconElement.cs" />
Expand Down

0 comments on commit b0d7cc8

Please sign in to comment.