Limit selection when DateSelectionMode="Month"

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.

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); 
    }        
} 

<Grid> 
    <Grid.Resources> 
        <local:MonthSelector x:Key="monthSelector"/> 
    </Grid.Resources> 
    <telerik:RadCalendar DateSelectionMode="Month" 
                         MonthButtonStyle="{x:Null}" 
                         MonthButtonStyleSelector="{StaticResource monthSelector}"/> 
</Grid> 
In this article
Not finding the help you need? Improve this article