Browse Source

Merge pull request #9581 from comesx4/disable-track-when-slider-is-disabled-on-sliding

bugfix: If the slider is disabled while sliding, prevent the track sliding
pull/9593/head
Max Katz 3 years ago
committed by GitHub
parent
commit
a6b7bf53a9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      src/Avalonia.Controls/Slider.cs
  2. 39
      src/Avalonia.Themes.Fluent/Controls/Slider.xaml

20
src/Avalonia.Controls/Slider.cs

@ -190,7 +190,7 @@ namespace Avalonia.Controls
_increaseButtonSubscription?.Dispose();
_increaseButtonReleaseDispose?.Dispose();
_pointerMovedDispose?.Dispose();
_decreaseButton = e.NameScope.Find<Button>("PART_DecreaseButton");
_track = e.NameScope.Find<Track>("PART_Track");
_increaseButton = e.NameScope.Find<Button>("PART_IncreaseButton");
@ -258,7 +258,7 @@ namespace Avalonia.Controls
e.Handled = handled;
}
private void MoveToNextTick(double direction)
{
if (direction == 0.0) return;
@ -317,6 +317,12 @@ namespace Avalonia.Controls
private void TrackMoved(object? sender, PointerEventArgs e)
{
if (!IsEnabled)
{
_isDragging = false;
return;
}
if (_isDragging)
{
MoveToPoint(e.GetCurrentPoint(_track));
@ -343,15 +349,15 @@ namespace Avalonia.Controls
return;
var orient = Orientation == Orientation.Horizontal;
var thumbLength = (orient
? _track.Thumb.Bounds.Width
var thumbLength = (orient
? _track.Thumb.Bounds.Width
: _track.Thumb.Bounds.Height) + double.Epsilon;
var trackLength = (orient
? _track.Bounds.Width
var trackLength = (orient
? _track.Bounds.Width
: _track.Bounds.Height) - thumbLength;
var trackPos = orient ? posOnTrack.Position.X : posOnTrack.Position.Y;
var logicalPos = MathUtilities.Clamp((trackPos - thumbLength * 0.5) / trackLength, 0.0d, 1.0d);
var invert = orient ?
var invert = orient ?
IsDirectionReversed ? 1 : 0 :
IsDirectionReversed ? 0 : 1;
var calcVal = Math.Abs(invert - logicalPos);

39
src/Avalonia.Themes.Fluent/Controls/Slider.xaml

@ -302,26 +302,6 @@
<Setter Property="IsVisible" Value="True" />
</Style>
<!-- Disabled State -->
<Style Selector="^:disabled">
<Style Selector="^ /template/ RepeatButton#PART_DecreaseButton">
<Setter Property="Background" Value="{DynamicResource SliderTrackValueFillDisabled}" />
</Style>
<Style Selector="^ /template/ RepeatButton#PART_IncreaseButton">
<Setter Property="Background" Value="{DynamicResource SliderTrackFillDisabled}" />
</Style>
<Style Selector="^ /template/ Thumb">
<Setter Property="Background" Value="{DynamicResource SliderThumbBackgroundDisabled}" />
</Style>
<Style Selector="^ /template/ TickBar">
<Setter Property="Fill" Value="{DynamicResource SliderTickBarFillDisabled}" />
</Style>
</Style>
<!-- PointerOver State -->
<Style Selector="^:pointerover">
<Style Selector="^ /template/ Grid#SliderContainer">
@ -362,6 +342,25 @@
</Style>
</Style>
<!-- Disabled State -->
<Style Selector="^:disabled">
<Style Selector="^ /template/ RepeatButton#PART_DecreaseButton">
<Setter Property="Background" Value="{DynamicResource SliderTrackValueFillDisabled}" />
</Style>
<Style Selector="^ /template/ RepeatButton#PART_IncreaseButton">
<Setter Property="Background" Value="{DynamicResource SliderTrackFillDisabled}" />
</Style>
<Style Selector="^ /template/ Thumb">
<Setter Property="Background" Value="{DynamicResource SliderThumbBackgroundDisabled}" />
</Style>
<Style Selector="^ /template/ TickBar">
<Setter Property="Fill" Value="{DynamicResource SliderTickBarFillDisabled}" />
</Style>
</Style>
<Style Selector="^:error">
<Setter Property="Foreground" Value="{DynamicResource SystemControlErrorTextForegroundBrush}" />
<Style Selector="^ /template/ Thumb">

Loading…
Cancel
Save