Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wpf TimeSpanUpDown increment seconds first

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 ?

like image 406
Tal Shaked Avatar asked Oct 20 '22 21:10

Tal Shaked


2 Answers

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.

like image 99
Il Vic Avatar answered Nov 15 '22 06:11

Il Vic


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.

like image 38
Jamey Avatar answered Nov 15 '22 06:11

Jamey