title | description | type | page_title | slug | position | tags | ticketid | res_type |
---|---|---|---|---|---|---|---|---|
Limit selection when DateSelectionMode="Month" |
Disable selection in Month DateSelectionMode. |
how-to |
Prevent certain months from being selected |
kb-datetimepicker-limit-selection-in-dateselectionmode-month |
0 |
limit, selection, dateselectionmode, month |
1425924 |
kb |
Product | RadDateTimePicker for WPF |
How to limit selection when the DateSelectionMode property is Month.
Create a custom StyleSelector and disable the months by setting the IsEnabled property of the CalendarButtonContent. After that, set the StyleSelector to the MonthButtonStyleSelector property of the RadDateTimePicker.
{{region kb-datetimepicker-limit-selection-in-dateselectionmode-month-0}}
public class MonthSelector : StyleSelector
{
public override Style SelectStyle(object item, DependencyObject container)
{
CalendarButtonContent content = item as CalendarButtonContent;
if (content != null)
{
var monthsToEnable = new List<string>() { "Mar", "Jun", "Sep", "Dec" };
if (!monthsToEnable.Contains(content.Text))
{
content.IsEnabled = false;
}
}
return base.SelectStyle(item, container);
}
}
{{endregion}}
{{region kb-datetimepicker-limit-selection-in-dateselectionmode-month-1}}
<Grid>
<Grid.Resources>
<local:MonthSelector x:Key="monthSelector"/>
</Grid.Resources>
<telerik:RadCalendar DateSelectionMode="Month"
MonthButtonStyle="{x:Null}"
MonthButtonStyleSelector="{StaticResource monthSelector}"/>
</Grid>
{{endregion}}