Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
845
How can I force the XamNumericSlider to only change the bound value in discrete steps?
posted

I've got a value that I want to change with a slider. It can vary from 1 to 100 and I'd like it to increment and decrement in steps of 0.1, but at the moment when I move the slider it changes the value in what's effectively a continuous manner.

This means that the value changes from 10 to 10.04589455 (say) which a) is meaningless for my application and b) ruins the layout of the page.

The `LargeChange` and `SmallChange` properties don't seem to affect this.

I can't round the value in the property setter as I'm binding to a property on an Entity, plus it seems to be the wrong approach for the problem.

How can I achieve this within the slider itself?

Parents
No Data
Reply
  • 845
    Verified Answer
    Offline posted

    I got round this by adding an `IValueConverter` to the `Value` binding:

        Value="{Binding NewPageTemplate.LabelHeight, Mode=TwoWay, Converter={StaticResource LabelSizeConverter}}"

    This is defined as:

        public class LabelSizeConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                return value;
            }
     
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                double size = (double)value;
     
                return Math.Round(size, 1);
            }
        }
Children