Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Commit 0ac1a50

Browse files
committed
Prevent mouse scroll from setting sliders outside the Min/Max
1 parent 78f3a77 commit 0ac1a50

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

OnnxStack.UI/Behaviors/SliderMouseWheelBehavior.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.Xaml.Behaviors;
2+
using Newtonsoft.Json.Linq;
23
using System.Windows.Controls;
34
using System.Windows.Input;
45

@@ -16,11 +17,19 @@ private void AssociatedObject_PreviewMouseWheel(object sender, MouseWheelEventAr
1617
var slider = (Slider)sender;
1718
if (e.Delta > 0)
1819
{
19-
slider.Value += slider.TickFrequency;
20+
var newValue = slider.Value + slider.TickFrequency;
21+
if (newValue > slider.Maximum)
22+
return;
23+
24+
slider.Value = newValue;
2025
}
2126
else
2227
{
23-
slider.Value -= slider.TickFrequency;
28+
var newValue = slider.Value - slider.TickFrequency;
29+
if (newValue < slider.Minimum)
30+
return;
31+
32+
slider.Value = newValue;
2433
}
2534
}
2635

0 commit comments

Comments
 (0)