MindFusion.Wpf Pack Programmer's Guide
Tutorial 2: Creating Recurrent Items

This tutorial shows how to programmatically create recurring items using Scheduling for WPF.

1. Create and initialize a new WPF application project

Follow steps 1 through 3 from the previous tutorial.

Set CurrentView to WeekRange, Date to Jan 1, 2010 and EndDate to Mar 1, 2010, respectively. Increase the size of the window to, say, 600x500.

2. Create an appointment

Create a new appointment in the handler of the window's Load event. To create the appointment, add the following lines of code to the body of the event handler.

 Note

Be sure to include both MindFusion.Scheduling and MindFusion.Scheduling.Wpf namespaces via the using (Imports in Visual Basic) keyword in the beginning of the file.

C#  Copy Code

Appointment app = new Appointment();
app.HeaderText = "Meet George";
app.DescriptionText = "This is a sample appointment";
app.StartTime = new DateTime(2010, 1, 10, 14, 0, 0);
app.EndTime = new DateTime(2010, 1, 10, 16, 30, 0);

calendar.Schedule.Items.Add(app);

Visual Basic  Copy Code

Dim app As New Appointment()
app.HeaderText = "Meet George"
app.DescriptionText = "This is a sample appointment"
app.StartTime = new DateTime(2010, 1, 10, 14, 0, 0)
app.EndTime = new DateTime(2010, 1, 10, 16, 30, 0)

calendar.Schedule.Items.Add(app)

The code above creates a new appointment on 10th of January, 2010, starting at 2:00 PM and ending at 4:30 PM.

3. Create the recurrence

Now that the appointment is added to the schedule, create a Recurrence object that defines how the appointment recurs. The following code creates and initializes a new Recurrence object and associates it with the item. Append these lines to the window's Load event handler.

C#  Copy Code

Recurrence rec = new Recurrence();
rec.Pattern = RecurrencePattern.Weekly;
rec.DaysOfWeek = DaysOfWeek.Monday | DaysOfWeek.Wednesday;
rec.Weeks = 2;
rec.StartDate = new DateTime(2010, 1, 10);
rec.RecurrenceEnd = RecurrenceEnd.Never;

app.Recurrence = rec;

Visual Basic  Copy Code

Dim rec As New Recurrence()
rec.Pattern = RecurrencePattern.Weekly
rec.DaysOfWeek = DaysOfWeek.Monday + DaysOfWeek.Wednesday
rec.Weeks = 2
rec.StartDate = new DateTime(2010, 1, 10)
rec.RecurrenceEnd = RecurrenceEnd.Never

app.Recurrence = rec

This fragment creates a new recurrence object that continues infinitely and repeats the appointment on Monday and Wednesday every two weeks.

4. Build and run

Compile and run the application. The image below depicts what the application output would look like.