diff --git a/src/Shared/HandyControl_Shared/Controls/Attach/ComboBoxAttach.cs b/src/Shared/HandyControl_Shared/Controls/Attach/ComboBoxAttach.cs new file mode 100644 index 00000000..b71aa6ed --- /dev/null +++ b/src/Shared/HandyControl_Shared/Controls/Attach/ComboBoxAttach.cs @@ -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); +} diff --git a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems index 5b0f109f..dea0bb2a 100644 --- a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems +++ b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems @@ -15,6 +15,7 @@ +