Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions FRBDK/Glue/Glue/Themes/Converters/ScrollThrottleBehavior.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
4 changes: 3 additions & 1 deletion FRBDK/Glue/Glue/Themes/Frb.Styles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
<Setter Property="TextOptions.TextRenderingMode" Value="Auto" />
</Style>

<Style TargetType="{x:Type ScrollViewer}" BasedOn="{StaticResource MaterialDesignScrollViewer}" />
<Style TargetType="{x:Type ScrollViewer}" BasedOn="{StaticResource MaterialDesignScrollViewer}">
<Setter Property="converters:ScrollThrottleBehavior.IsEnabled" Value="True" />
</Style>

<Style TargetType="{x:Type ScrollBar}" BasedOn="{StaticResource MaterialDesignScrollBar}">
<Style.Resources>
Expand Down