To allow full templating and special days support RadCalendar defines 2 properties – ItemTemplate and
ItemTemplateSelector.
By using the ItemTemplate you can specify how each of the days will be rendered. The DataContext of each day is of type
Telerik.Windows.Controls.CalendarButtonContentInfo.
Here is a sample data template for a day:
CopyXAML
<telerikInput:RadCalendar>
<telerikInput:RadCalendar.ItemTemplate>
<DataTemplate>
<Grid Margin="5">
<TextBlock Text="{Binding DetailText}" FontSize="7" MaxHeight="25" VerticalAlignment="Top" Margin="0,-2,0,0" />
<TextBlock Text="{Binding Text}" VerticalAlignment="Bottom" HorizontalAlignment="Left" />
</Grid>
</DataTemplate>
</telerikInput:RadCalendar.ItemTemplate>
</telerikInput:RadCalendar>
Using ItemTemplateSelector
To mark specific day or days with as a special RadCalendar provides an ItemTemplateSelector property. Here how to create simple template
selector and to mark the non-working days as special:
CopyXAML
<UserControl.Resources>
<local:WeekendDaySelector x:Key="WeekendDaySelector">
<local:WeekendDaySelector.SpecialTemplate>
<DataTemplate>
<Grid Margin="5">
<Image Source="/Calendar/Images/SpecialDay.png" Width="24" Height="24" />
<TextBlock Text="{Binding Text}" x:Name="TextPresenter" VerticalAlignment="Bottom" HorizontalAlignment="Left" />
</Grid>
</DataTemplate>
</local:WeekendDaySelector.SpecialTemplate>
</local:WeekendDaySelector>
</UserControl.Resources>
CopyC#
public class WeekendDaySelector : DataTemplateSelector
{
public DataTemplate SpecialTemplate
{
get;
set;
}
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
CalendarButtonContentInfo info = item as CalendarButtonContentInfo;
CalendarButton button = container as CalendarButton;
if (!button.IsFromCurrentView) return null;
if (info.Date == null) return null;
if (info.Date.Value.DayOfWeek == DayOfWeek.Saturday ||
info.Date.Value.DayOfWeek == DayOfWeek.Sunday)
{
return SpecialTemplate;
}
return base.SelectTemplate(item, container);
}
}