Interval in .NET MAUI Range Slider (SfDateTimeRangeSlider)

24 Nov 20225 minutes to read

This section explains how to add the interval for the DateTime Range Slider.

Date interval

DateTime Range Slider elements like labels, ticks, and dividers are rendered based on the Interval, Minimum, and Maximum properties. The default value is 0.

Change the interval type using the IntervalType property. Format or change the label text using the DateFormat property.

For example, if the Minimum is DateTime(2000, 01, 01), the Maximum is DateTime(2005, 01, 01), and Interval is 1, IntervalType is SliderDateIntervalType.Years, DateFormat is yyyy then the Range Slider will render the labels, major ticks, and dividers at 2000, 2001, 2002, and so on.

<sliders:SfDateTimeRangeSlider Minimum="2000-01-01" 
                               Maximum="2004-01-01" 
                               RangeStart="2001-01-01" 
                               RangeEnd="2003-01-01"
                               Interval="1" 
                               IntervalType="Years"
                               DateFormat="yyyy" 
                               ShowLabels="True" 
                               ShowTicks="True" 
                               ShowDividers="True">
</sliders:SfDateTimeRangeSlider>
SfDateTimeRangeSlider rangeSlider = new SfDateTimeRangeSlider();
rangeSlider.Minimum = new DateTime(2000, 01, 01);
rangeSlider.Maximum = new DateTime(2004, 01, 01);
rangeSlider.RangeStart = new DateTime(2001, 01, 01); 
rangeSlider.RangeEnd = new DateTime(2003, 01, 01);            
rangeSlider.Interval = 1;
rangeSlider.IntervalType = SliderDateIntervalType.Years;
rangeSlider.DateFormat = "yyyy";
rangeSlider.ShowLabels = true;
rangeSlider.ShowTicks = true;
rangeSlider.ShowDividers = true;

RangeSlider date interval

Auto interval

If the ShowTicks or ShowLabels, or ShowDividers properties are True, but the Interval is 0, the Interval will be calculated from the available size. If the IntervalType or DateFormat properties are not set, their values too will be calculated.

For example, if the Minimum is DateTime(2000, 01, 01), the Maximum is DateTime(2001, 01, 01), Interval is 0, and consider the available size as 350, then the Range Slider will render the labels, major ticks, and dividers at Jan 01, 2000, Jul 01, 2000, and Nov 01, 2000 respectively.

<sliders:SfDateTimeRangeSlider Minimum="2000-01-01" 
                               Maximum="2004-01-01" 
                               RangeStart="2001-01-01" 
                               RangeEnd="2003-01-01"
                               ShowLabels="True" 
                               ShowTicks="True" 
                               ShowDividers="True">
</sliders:SfDateTimeRangeSlider>
SfDateTimeRangeSlider rangeSlider = new SfDateTimeRangeSlider();
rangeSlider.Minimum = new DateTime(2000, 01, 01);
rangeSlider.Maximum = new DateTime(2004, 01, 01);
rangeSlider.RangeStart = new DateTime(2001, 01, 01); 
rangeSlider.RangeEnd = new DateTime(2003, 01, 01);            
rangeSlider.ShowLabels = true;
rangeSlider.ShowTicks = true;
rangeSlider.ShowDividers = true;