It is a common scenario when we would like to limit the selectable values in a time or date picker control. Normally we would do this by setting an allowed date-time range but a more sophisticated case is when we also want to filter out some selection possibilities and allow only specific ones. Imagine an application that provides the end-user with the possibility to create reminders that can only happen in time intervals of 15 minutes:
3:00 AM, 3:15 AM, 3:30 AM...
Here we don’t want to prevent the user from selecting values from the whole time-range, but want to make some restrictions like allowing only 15-minutes based values. Until now doing this for Windows Phone 7 would not be a trivial task but as of Q3 2011 SP1 of RadControls for Windows Phone 7 this is made easy with a new feature exposed both by RadDate- and RadTimePicker: the Step support.
Both controls expose the Step property which is of the DateTime type. Depending on the control (RadTimePicker or RadDatePicker) the Date or the TimeOfDay values encapsulated by the DateTime struct are used to define the value intervals. Let’s say we want to create a DatePicker that allows selecting only even months and days that are multiples of 5. We would do this in the following way with RadDatePicker:
As you can see, the value of the Step property is composed to define time steps of 2 for the months and 5 for the days. The years component is left to be with a step of 1 year which is the default value. The result is demonstrated on the screenshot below:
The same approach is applicable when using RadTimePicker except that the date-time components in the DateTime struct being used are those who define the TimeOfDay value, i.e. hours and minutes. So if we want to restrict the user to select only time values with 30-minutes intervals, we should set the TimeStep property the following way:
Furthermore, the RadDatePicker control exposes the DayStepBehavior, MonthStepBehavior and YearStepBehavior properties which can be used to fine-tune the behavior of the control when non-default Step is defined. These properties accept one of the three possible values defined by the DateStepBehavior enumeration:
Selecting the MultiplesOnly value means that values will be selectable for the given date component that are multiples of the defined step. Let’s say that we have defined 3 as a step for the days selector. The following days of the month will be made available for selection:
3, 6, 9, 12, 15, 18...
Selecting the BaseAndMultiples value means that besides the values that are multiples of the time step, the base value will also be included. In the case of defining 3 as a time step for the days selector, the possible selection options will be:
1, 3, 6, 9, 12, 15, 18...
The last option, StartFromBase, implies that the selectable values will start from the base value and will increase in arithmetic progression, i.e. each next value will be equal to the previous plus the time step defined. In the case of having 3 as a time step for the day selection, the selection options will be:
1, 4, 7, 10, 13, 16, 19...
Pretty nice feature indeed!
Check it out by downloading our latest release: RadControls for Windows Phone 7 Q3 2011 SP1 and give us feedback!