Category / Section
How to increment and decrement the interval value of TimeSpanEdit?
1 min read
By default, the interval to increment or decrement the value of TimeSpanEdit will be 1(one). We can increment or decrement an interval value of TimeSpanEdit by handling PreviewMouseDown event. In this example, value(minutes) of TimeSpanEdit will be incremented or decremented using PreviewMouseDown event.
<syncfusion:TimeSpanEdit x:Name="timespanedit" Value="2:25:52" Format=" h 'hours' m 'minutes' :s 'sec' z 'msec'" Width="250" Height="40" />
public MainWindow() { InitializeComponent(); timespanedit.Loaded += Timespanedit_Loaded; } RepeatButton upbutton = null; RepeatButton downbutton = null; private void Timespanedit_Loaded(object sender, RoutedEventArgs e) { if (upbutton == null && downbutton == null) { upbutton = timespanedit.Template.FindName("upbutton", timespanedit) as RepeatButton; downbutton = timespanedit.Template.FindName("downbutton", timespanedit) as RepeatButton; if (upbutton != null) upbutton.PreviewMouseDown += new MouseButtonEventHandler(Timespanedit_PreviewMouseDown); if (downbutton != null) downbutton.PreviewMouseDown += new MouseButtonEventHandler(Timespanedit_PreviewMouseDown1); } } private void Timespanedit_PreviewMouseDown1(object sender, MouseButtonEventArgs e) { timespanedit.Value -= new TimeSpan(0, 15, 0); e.Handled = true; } void Timespanedit_PreviewMouseDown(object sender, MouseButtonEventArgs e) { timespanedit.Value += new TimeSpan(0, 15, 0); e.Handled = true; }
Output: