Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Range Slider Upper/Lower value coercion #3798

Closed
lipchev opened this issue May 17, 2020 · 1 comment
Closed

Range Slider Upper/Lower value coercion #3798

lipchev opened this issue May 17, 2020 · 1 comment
Labels
Milestone

Comments

@lipchev
Copy link
Contributor

lipchev commented May 17, 2020

The actual position of the upper/lower thumbs may become out of sync with the actual values, when the coercion of the bound properties takes effect during dragging operations.

To Reproduce

Consider the following dependency property:

    public static readonly DependencyProperty MaxValueDisplayedProperty = DependencyProperty.Register(
        "MaxValueDisplayed", typeof(double), typeof(MainWindow), new PropertyMetadata(75d, PropertyChangedCallback, CoerceValueCallback ));

    private static object CoerceValueCallback(DependencyObject dependencyObject, object baseValue)
    {
        var value = (double) baseValue;
        if (value < 50)
            return 50.0;
        return baseValue;
    }

Steps to reproduce the behavior:

  1. Start dragging the UpperThumb (e.g. the right thumb with initial value of 75) towards the LowerLimit (0 in our case)
  2. As the UpperLimit reaches 50 the value is coerced to 50 (both the MaxValueDisplayed and the RangeSlider.UpperLimit show 50)
  3. The user is however free to drag on - that is the actual thumb position becomes out of sync with the current value
  4. Even after releasing the mouse button, the position of the thumb is out of sync
  5. The behavior is the same regardless of whether we're dragging the whole range or just the upper tracker.

Expected behavior
The thumb position respects the coerced value at all times: similar to how the slider stops moving when reaching the same coercion limit (3rd screenshot)

Screenshots
image
image
image

Environment:

  • MahApps.Metro version [both v1.6.4 & 2.0.0-alpha0821]
  • OS: [Win10]
  • Visual Studio [2017]
  • .NET Framework [4.7.2]

Repo
Here is the very simple example from the screenshots, with the very basic designer definition:

        <mah:RangeSlider Minimum="0" Maximum="100" LowerValue="25" UpperValue="{Binding MaxValueDisplayed}"  x:Name="RangeSlider"/>
        <Slider Minimum="0" Maximum="100" Value="{Binding MaxValueDisplayed}" Grid.Row="1" x:Name="Slider"/>
        <UniformGrid Columns="3" Grid.Row="2">
            <mah:MetroHeader Header="RangeSlider.UpperValue" Content="{Binding ElementName=RangeSlider, Path=UpperValue}" />
            <mah:MetroHeader Header="Slider.Value" Content="{Binding ElementName=Slider, Path=Value}" />
            <mah:MetroHeader Header="Max Value Displayed" Content="{Binding MaxValueDisplayed}" />
        </UniformGrid>
@punker76 punker76 added the Bug label May 22, 2020
@punker76 punker76 added this to the 2.0.0 milestone May 22, 2020
punker76 added a commit that referenced this issue May 22, 2020
- Use RangeSelectionChangedEventHandler<T> and RangeSelectionChangedEventArgs<T>
- Use RoutedPropertyChangedEventHandler<T> and RoutedPropertyChangedEventArgs<T>
punker76 added a commit that referenced this issue May 22, 2020
Fix RangeSlider Upper/Lower value coercion and value changed events
@punker76
Copy link
Member

@lipchev This is now fixed and will be available with next v2.0 release. Thx for using the latest alpha hot stuff and reporting the issue. And thx for the sample! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants