enhance: add IsMouseWheelEnabled attach property.
This commit is contained in:
1 parent
c058343d55
commit
b0d7cc8636
2 files changed
+46
No files matched your search
@@ -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);
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\DataGridAttach.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\DataGridAttach.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\DropDownElement.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\DropDownElement.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\EdgeElement.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\GridAttach.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\GridViewAttach.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\GridViewAttach.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\IconElement.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\IconElement.cs" />
|
||||||
|
|||||||
Reference in new issue
Block a user