Skip to content

Latest commit

 

History

History
64 lines (54 loc) · 1.91 KB

kb-datetimepicker-limit-selection-in-dateselectionmode-month.md

File metadata and controls

64 lines (54 loc) · 1.91 KB
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

Environment

Product RadDateTimePicker for WPF

Description

How to limit selection when the DateSelectionMode property is Month.

Solution

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.

[C#]

{{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}}

[XAML]

{{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}}