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
350
XamNumericEditor's dynamic SpinIncrement?
posted

Hi,

I need to have XamNumericEditor's SpinIncrement value depend on the current editor's value. For example:

- if value is in the range of 0 - 100, the increment must be 1

- if value is in the range of 100-1000, the increment must be 10

- if value is above 1000, the increment must be 1000

Is there any way to achieve the above mentioned functionality using XamNumericEditor?

Thanks,

Alex

Parents
  • 22852
    Verified Answer
    Offline posted

    Alex,

    Another approach would be to bind the SpinIncrement property to the Value property and use a converter to set the increment.  For example:

    XAML:

    <Grid>
        <Grid.Resources>
            <local:SpinIncrementConverter x:Key="SpinIncrementConverter"/>
        </Grid.Resources>
        <igEditors:XamNumericEditor SpinButtonDisplayMode="Always" SpinIncrement="{Binding RelativeSource={RelativeSource Self}, Path=Value, Mode=OneWay, Converter={StaticResource SpinIncrementConverter}}"></igEditors:XamNumericEditor>
    </Grid>

    C#:

    public class SpinIncrementConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double newValue = 0;
            int increment = 1;
            if (value is double)
            {
                newValue = (double)value;


                if (newValue >= 100)
                    increment = 10;
                if (newValue >= 1000)
                    increment = 1000;
            }
            return increment;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    Let me know if you have any questions with this matter.

Reply Children
No Data