diff --git a/FRBDK/Glue/Glue/Themes/Converters/ScrollThrottleBehavior.cs b/FRBDK/Glue/Glue/Themes/Converters/ScrollThrottleBehavior.cs new file mode 100644 index 000000000..217025245 --- /dev/null +++ b/FRBDK/Glue/Glue/Themes/Converters/ScrollThrottleBehavior.cs @@ -0,0 +1,43 @@ +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; + +namespace FlatRedBall.Glue.Themes.Converters; + +public static class ScrollThrottleBehavior +{ + public static readonly DependencyProperty IsEnabledProperty = + DependencyProperty.RegisterAttached( + "IsEnabled", + typeof(bool), + typeof(ScrollThrottleBehavior), + new PropertyMetadata(false, OnIsEnabledChanged)); + + public static bool GetIsEnabled(ScrollViewer obj) => (bool)obj.GetValue(IsEnabledProperty); + public static void SetIsEnabled(ScrollViewer obj, bool value) => obj.SetValue(IsEnabledProperty, value); + + private static void OnIsEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is ScrollViewer scrollViewer + ) + { + if ((bool)e.NewValue) + { + scrollViewer.PreviewMouseWheel += OnMouseWheel; + } + else + { + scrollViewer.PreviewMouseWheel -= OnMouseWheel; + } + } + } + + private static void OnMouseWheel(object sender, MouseWheelEventArgs e) + { + if (sender is ScrollViewer scrollViewer && System.Math.Abs(e.Delta) != 120) + { + scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset + ((double)e.Delta /120)); + e.Handled = true; + } + } +} diff --git a/FRBDK/Glue/Glue/Themes/Frb.Styles.xaml b/FRBDK/Glue/Glue/Themes/Frb.Styles.xaml index b50ee3e8a..1b7d3efdf 100644 --- a/FRBDK/Glue/Glue/Themes/Frb.Styles.xaml +++ b/FRBDK/Glue/Glue/Themes/Frb.Styles.xaml @@ -39,7 +39,9 @@ -