wpf TimeSpanUpDown increment seconds first

1.9k Views Asked by At

I'm using Extended WPF Toolkit.

https://wpftoolkit.codeplex.com/wikipage?title=TimeSpanUpDown

When I click the arrow, by default it increases the value of hours .

Is there a way to make it increase the seconds first as a default behavior ?

2

There are 2 best solutions below

0
On

I would extend the WPF Toolkit TimeSpanUpDown control in this way:

public class TimeSpanUpDown : Xceed.Wpf.Toolkit.TimeSpanUpDown
{
    protected override void OnIncrement()
    {
        if (Value.HasValue)
        {
            UpdateTimeSpan(1);
        }
        else
        {
            Value = DefaultValue ?? TimeSpan.Zero;
        }
    }

    protected override void OnDecrement()
    {
        if (Value.HasValue)
        {
            UpdateTimeSpan(-1);
        }
        else
        {
            Value = DefaultValue ?? TimeSpan.Zero;
        }
    }

    private void UpdateTimeSpan(int value)
    {
        TimeSpan timeSpan = (TimeSpan)Value;
        timeSpan = timeSpan.Add(new TimeSpan(0, 0, 0, value, 0));

        if (IsLowerThan(timeSpan, Minimum))
        {
            Value = Minimum;
            return;
        }

        if (IsGreaterThan(timeSpan, Maximum))
        {
            Value = Maximum;
            return;
        }

        Value = timeSpan;
    }

}

In this way if you click the Arrow you increase just the seconds.

0
On

if you use the add the property CurrentDateTimePart="Second" to the TimeSpanUpDown element in your xaml, you will get the desired effect. This simply sets the default DateTimePart on first load, and the keyboard controls still work as expected.