-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance: add IsMouseWheelEnabled attach property.
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/Shared/HandyControl_Shared/Controls/Attach/ComboBoxAttach.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters