For example:
public class AppointmentTemplateSelector : DataTemplateSelector |
{ |
public DataTemplate RedAppointmentTemplate { get; set; } |
public DataTemplate GreenAppointmentTemplate { get; set; } |
public override DataTemplate SelectTemplate(object item, DependencyObject container) |
{ |
base.SelectTemplate(item, container); |
AppointmentSlot appointmentSlot = item as AppointmentSlot; |
var appointment = appointmentSlot.Occurrence.Appointment; |
if (appointment != null && appointment.Start.Date == DateTime.Today) |
{ |
return RedAppointmentTemplate; |
} |
return GreenAppointmentTemplate; |
} |
} |
Then you need to define two DataTemplates – one for the “red” appointments and another for the “green” appointments:
<DataTemplate x:Key="RedAppointmentTemplate"> |
<Border Background="Red” |
BorderThickness="1" |
CornerRadius="8" Margin="-2"> |
<TextBox x:Name="PART_SubjectTextBox" Margin="7 0 18 0" |
VerticalAlignment="Top" HorizontalAlignment="Left" |
Text="{Binding Path=Occurrence.Appointment.Subject}" |
Foreground="Black" TextWrapping="Wrap" MaxWidth="100" /> |
</Border> |
</DataTemplate> |
<DataTemplate x:Key="GreenAppointmentTemplate"> |
<Border Background="LightGreen” |
BorderThickness="1" |
CornerRadius="8" Margin="-2"> |
<TextBox x:Name="PART_SubjectTextBox" Margin="7 0 18 0" |
VerticalAlignment="Top" HorizontalAlignment="Left" |
Text="{Binding Path=Occurrence.Appointment.Subject}" |
Foreground="Black" TextWrapping="Wrap" MaxWidth="100" /> |
</Border> |
</DataTemplate> |
Add the AppointmentTemplateSelector to the resources:
<local:AppointmentTemplateSelector x:Key="ItemTemplateSelector" |
RedAppointmentTemplate ="{StaticResource RedAppointmentTemplate}" |
GreenAppointmentTemplate ="{StaticResource GreenAppointmentTemplate }" /> |
Set the AppointmentTemplateSelector property of RadScheduler:
<telerik:RadScheduler x:Name="scheduler" AppointmentTemplateSelector="{StaticResource ItemTemplateSelector}" /> |
The result of the above code will be red today’s appointments, whereas all other appointments will appear in green:
Download the source code for Silverlight and stay tuned for more in our Q2 release.
Rossitza Fakalieva is a Technical Manager, Microsoft MVP in Developer Technologies and a Director of the Bulgarian chapter of the global Women Who Code organization. She previously worked on the Telerik engineering team and defines herself as .NET enthusiast. She loves to empower others to grow in their career and in the tech field—by teaching, by delivering courses and presentations, and as part of her daily job.