RadControls for Silverlight

RadScheduler is an advanced Silverlight control providing full Blend support. From within the visual environment of Blend, you can easily perform various tasks such as editing control properties, modifying themes, creating and modifying templates and more.

This tutorial will walk you through the creation of a RadScheduler and will show you how to:

Note

Before reading this tutorial you should get familiar with the Visual Structure of the standard RadScheduler control and its Views and Dialogs.

For the purpose of this tutorial, you will need to create an empty Silverlight Application project and open it in Blend.

Note

In order to use RadScheduler control in your projects you have to add references to the following assemblies:

  1. Telerik.Windows.Controls
  2. Telerik.Windows.Controls.Input
  3. Telerik.Windows.Controls.Navigation
  4. Telerik.Windows.Data

You can find more info herehere.

Add RadScheduler

  • Open the Asset Library (Window->Assets) in Expression Blend and start writing the name of the RadScheduler in the search box.

 

  • Drag a RadScheduler on the artboard.

 

CopyXAML
<UserControl
...
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"

....>
  <Grid x:Name="LayoutRoot">
   <telerik:RadScheduler/>
  </Grid>
</UserControl>

There are two things you should pay attention to in the above code snipped. The first is the declaration of the Telerik.Windows.Controls namespace from Telerik.Windows.Controls.Scheduler assembly and the second is the declaration of the RadScheduler control itself.

If you run your application now you will see an empty RadScheduler that contains no appointments. To learn how to add/edit/delete appointments run-time, take a look at the End-User Capabilities Overview topic.

Add Appointments Programmatically

The appointments in RadScheduler are represented by the Telerik.Window.Controls.Scheduler.Appointment class. In order to add an appointment you should create Appointment class instance, set its properties (Subject, Start, End, Body, Category etc) and add it to the RadScheduler'sAppointments collection property.

CopyC#
Appointment meetingAppointment = new Appointment();
meetingAppointment.Subject = "Meet Mark";
meetingAppointment.Start = DateTime.Now.AddHours(3);
meetingAppointment.End = meetingAppointment.Start.AddHours( 1.5 );
meetingAppointment.Category = Categories.GreenCategory;

radScheduler.Appointments.Add( meetingAppointment );
CopyVB.NET
Dim meetingAppointment As New Appointment()
meetingAppointment.Subject = "Meet Mark"
meetingAppointment.Start = DateTime.Now.AddHours(3)
meetingAppointment.[End] = meetingAppointment.Start.AddHours(1.5)
meetingAppointment.Category = Categories.GreenCategory

radScheduler.Appointments.Add(meetingAppointment)

On the snapshot below you can see that the newly created appointment 'Meet Mark' is added to the RadScheduler.

 

To learn more about the RadScheduler's appointments take a look at the Appointments Overview topic.

Bind RadScheduler to Collection of Appointments

In oder to bind a RadScheduler you should create a collection of Appointment objects, and then set it as data source via the AppointmentsSource property. These appointments can be obtained from different kind of web service, data base or might be created manually as it is explained in the Populating with Data Overview.

To illustrate the idea, a sample method named CreateSampleData() can be implemented. It creates and returns a collection of three appointments.

CopyC#
private DefaultAppointmentCollection CreateSampleData()
{
    DefaultAppointmentCollection appointments = new DefaultAppointmentCollection();

    Appointment fitnessAppointment = new Appointment();
    fitnessAppointment.Subject = "Fitness";
    fitnessAppointment.Start = DateTime.Now;
    fitnessAppointment.End = DateTime.Now.AddHours( 2 );
    fitnessAppointment.Category = Categories.BlueCategory;
    appointments.Add( fitnessAppointment );

    Appointment salaryAppointment = new Appointment();
    salaryAppointment.Subject = "Salary";
    salaryAppointment.Start = CalendarHelper.GetStartOfMonth( DateTime.Today.Year, DateTime.Today.Month ).AddHours( 8 );
    salaryAppointment.End = salaryAppointment.Start.AddHours( 1 );
    salaryAppointment.Category = Categories.RedCategory;
    salaryAppointment.Importance = Importance.High;
    appointments.Add( salaryAppointment );

    Appointment meetingAppointment = new Appointment();
    meetingAppointment.Subject = "Meet Mark";
    meetingAppointment.Start = DateTime.Now;
    meetingAppointment.End = meetingAppointment.Start.AddHours( 2 );
    meetingAppointment.Category = Categories.YellowCategory;
    appointments.Add( meetingAppointment );

    return appointments;
}
CopyVB.NET
Private Function CreateSampleData() As DefaultAppointmentCollection
    Dim appointments As New DefaultAppointmentCollection()

    Dim fitnessAppointment As New Appointment()
    fitnessAppointment.Subject = "Fitness"
    fitnessAppointment.Start = DateTime.Now
    fitnessAppointment.[End] = DateTime.Now.AddHours(2)
    fitnessAppointment.Category = Categories.BlueCategory
    appointments.Add(fitnessAppointment)

    Dim salaryAppointment As New Appointment()
    salaryAppointment.Subject = "Salary"
    salaryAppointment.Start = CalendarHelper.GetStartOfMonth(DateTime.Today.Year, DateTime.Today.Month).AddHours(8)
    salaryAppointment.[End] = salaryAppointment.Start.AddHours(1)
    salaryAppointment.Category = Categories.RedCategory
    salaryAppointment.Importance = Importance.High
    appointments.Add(salaryAppointment)

    Dim meetingAppointment As New Appointment()
    meetingAppointment.Subject = "Meet Mark"
    meetingAppointment.Start = DateTime.Now
    meetingAppointment.[End] = meetingAppointment.Start.AddHours(2)
    meetingAppointment.Category = Categories.YellowCategory
    appointments.Add(meetingAppointment)

    Return appointments
End Function

Now, let's bind the RadScheduler to the sample appointments collection returned by the CreateSampleData() method.

CopyC#
radScheduler.AppointmentsSource = this.CreateSampleData();
CopyVB.NET
radScheduler.AppointmentsSource = Me.CreateSampleData()

And here is the final result:

 

To learn more about the RadScheduler's data binding take a look at the Data Binding Support Overview topic.

Define Recurrent Appointments

RadScheduler includes support for recurring events on daily, weekly, monthly and yearly basis. Exceptions to the recurrence rules are also permitted. To support this recurrence behavior, the IAppointment interface includes the RecurrenceRule property. When an appointment is promoted into a recurring event, its RecurrenceRule is set with correct RecurrencePattern.

Below you can see how to create a daily recurrence pattern, that specifies a limit of 4 occurrences for the appointment.

CopyC#
Appointment fitnessAppointment = new Appointment();
fitnessAppointment.Subject = "Fitness";
fitnessAppointment.Start = DateTime.Today.AddHours( 7 );
fitnessAppointment.End = DateTime.Today.AddHours( 9 );
fitnessAppointment.Category = Categories.BlueCategory;

RecurrencePattern pattern = new RecurrencePattern();
pattern.Frequency = RecurrenceFrequency.Daily;
pattern.DaysOfWeekMask = RecurrenceDays.EveryDay;
pattern.MaxOccurrences = 4;
fitnessAppointment.RecurrenceRule = new RecurrenceRule( pattern );

radScheduler.Appointments.Add( fitnessAppointment );
CopyVB.NET
Dim fitnessAppointment As New Appointment()
fitnessAppointment.Subject = "Fitness"
fitnessAppointment.Start = DateTime.Today.AddHours(7)
fitnessAppointment.[End] = DateTime.Today.AddHours(9)
fitnessAppointment.Category = Categories.BlueCategory

Dim pattern As New RecurrencePattern()
pattern.Frequency = RecurrenceFrequency.Daily
pattern.DaysOfWeekMask = RecurrenceDays.EveryDay
pattern.MaxOccurrences = 4
fitnessAppointment.RecurrenceRule = New RecurrenceRule(pattern)

radScheduler.Appointments.Add(fitnessAppointment)

And here you can see the four appointments generated according to the specified recurrence rule. Notice the two rotating arrows placed in the right part of each appointment, they mark that the particular appointment is recurrent.

 

Define Exceptions to Recurrent Appointments

The RecurrenceRule class exposes an Exceptions property, which allows you to get all exception occurrences associated with the current rule. To define exceptions use the AddException() method, which has two overloads:

  • The first one accepts only the exception date as a parameter. If it is used then the particular occurrence of the appointment for that date will be removed.
  • The second overload also accepts the date parameter plus an exception appointment. If it is used then the passed exception appointment will be added as an exception to the rule. All exception appointments have their rotating recurrent arrows crossed off by a thin line (as it is shown in the Visual Structure topic).

To illustrate the usage of the first overload you are going to remove the third occurrence of the fitness appointment defined in the example above.

CopyC#
Appointment fitnessAppointment = new Appointment();
fitnessAppointment.Subject = "Fitness";
fitnessAppointment.Start = DateTime.Today.AddHours( 7 );
fitnessAppointment.End = DateTime.Today.AddHours( 9 );
fitnessAppointment.Category = Categories.BlueCategory;

RecurrencePattern pattern = new RecurrencePattern();
pattern.Frequency = RecurrenceFrequency.Daily;
pattern.DaysOfWeekMask = RecurrenceDays.EveryDay;
pattern.MaxOccurrences = 4;
fitnessAppointment.RecurrenceRule = new RecurrenceRule( pattern );

fitnessAppointment.RecurrenceRule.AddException( fitnessAppointment.Start.AddDays( 2 ) );

radScheduler.Appointments.Add( fitnessAppointment );
CopyVB.NET
Dim fitnessAppointment As New Appointment()
fitnessAppointment.Subject = "Fitness"
fitnessAppointment.Start = DateTime.Today.AddHours(7)
fitnessAppointment.[End] = DateTime.Today.AddHours(9)
fitnessAppointment.Category = Categories.BlueCategory

Dim pattern As New RecurrencePattern()
pattern.Frequency = RecurrenceFrequency.Daily
pattern.DaysOfWeekMask = RecurrenceDays.EveryDay
pattern.MaxOccurrences = 4
fitnessAppointment.RecurrenceRule = New RecurrenceRule(pattern)

fitnessAppointment.RecurrenceRule.AddException(fitnessAppointment.Start.AddDays(2))

radScheduler.Appointments.Add(fitnessAppointment)

And here is the result. Notice how the third appointment is no longer available.

 

And now to illustrate the usage of the second overload you are going to make exceptional the third occurrence of the fitness appointment defined in the example above.

CopyC#
Appointment fitnessAppointment = new Appointment();
fitnessAppointment.Subject = "Fitness";
fitnessAppointment.Start = DateTime.Today.AddHours( 7 );
fitnessAppointment.End = DateTime.Today.AddHours( 9 );
fitnessAppointment.Category = Categories.BlueCategory;

RecurrencePattern pattern = new RecurrencePattern();
pattern.Frequency = RecurrenceFrequency.Daily;
pattern.DaysOfWeekMask = RecurrenceDays.EveryDay;
pattern.MaxOccurrences = 4;
fitnessAppointment.RecurrenceRule = new RecurrenceRule( pattern );

Appointment exceptionAppointment = ( Appointment )fitnessAppointment.Copy();
exceptionAppointment.Start = fitnessAppointment.Start.AddDays( 2 );
exceptionAppointment.End = exceptionAppointment.Start.AddHours( 2 );
fitnessAppointment.RecurrenceRule.AddException( fitnessAppointment.Start.AddDays( 2 ), exceptionAppointment );

radScheduler.Appointments.Add( fitnessAppointment );
CopyVB.NET
Dim fitnessAppointment As New Appointment()
fitnessAppointment.Subject = "Fitness"
fitnessAppointment.Start = DateTime.Today.AddHours(7)
fitnessAppointment.[End] = DateTime.Today.AddHours(9)
fitnessAppointment.Category = Categories.BlueCategory

Dim pattern As New RecurrencePattern()
pattern.Frequency = RecurrenceFrequency.Daily
pattern.DaysOfWeekMask = RecurrenceDays.EveryDay
pattern.MaxOccurrences = 4
fitnessAppointment.RecurrenceRule = New RecurrenceRule(pattern)

Dim exceptionAppointment As Appointment = DirectCast(fitnessAppointment.Copy(), Appointment)
exceptionAppointment.Start = fitnessAppointment.Start.AddDays(2)
exceptionAppointment.[End] = exceptionAppointment.Start.AddHours(2)
fitnessAppointment.RecurrenceRule.AddException(fitnessAppointment.Start.AddDays(2), exceptionAppointment)

radScheduler.Appointments.Add(fitnessAppointment)

And here is the result. Notice how the third appointment has its recurrent arrows crossed off.

 

Note

If the user modifies an individual appointment occurrence, an exception is created. Which exception is added to the ReccurenceRule of the master appointment along with its specific date.

If you want to dive deeper into the recurrence feature of the RadScheduler, check out the following topics:

References

See Also