MindFusion.Scheduling for Silverlight Programmer's Guide
Customizing the Item Styles

As described in Customizing the Item Settings, the appearance of each item is controlled through four CalendarStyle objects - one for each state of the item (normal, selected, pointed, and pointed and selected). The default four styles for all items can be found in the ItemSettings object returned by the Calendar.ItemSettings property.

To customize the appearance of an individual item, associate a CalendarStyle objects with it by calling one of the following Calendar methods: SetItemStyle, SetSelectedItemStyle, SetPointedItemStyle and SetPointedSelectedItemStyle properties. The particular style that will be used when the item is rendered depends on the state of the item. The style set through SetItemStyle is used when the item is neither selected nor the mouse hovers over it. The style set through SetSelectedItemStyle is used when the item is selected and the mouse is not over it. The style set through SetPointedItemStyle is used when the mouse is over a non-selected item and, finally, the style set through SetPointedSelectedItemStyle is used when the item is selected and the mouse is over it at the same time. The "pointed item" styles are considered extended styles and are only used if ItemSettings.UseExtendedStyles is set to true. The item styles support the cascading paradigm described in Styles and Themes. The most general item styles are defined in the current theme. They cannot be changed by any means except by changing the theme itself. The styles defined in Calendar.ItemSettings are of higher priority and any of their properties that are explicitly specified will be used prior those from the theme. The styles defined for individual items are of highest priority and will always be used first, when present.

The following code defines a sample Calendar control in XAML:

XAML  Copy Code

<planner:Calendar x:Name="calendar" Theme="Vista" Date="1, 1, 2010" />

Create two items and add them to the above control using the following code:

C#  Copy Code

Appointment a = new Appointment();
a.StartTime = new DateTime(2010, 1, 1);
a.EndTime = new DateTime(2010, 1, 2);
a.HeaderText = "a";
calendar.Schedule.Items.Add(a);

Appointment b = new Appointment();
b.StartTime = new DateTime(2010, 1, 3);
b.EndTime = new DateTime(2010, 1, 4);
b.HeaderText = "b";
calendar.Schedule.Items.Add(b);

Visual Basic  Copy Code

Dim a As New Appointment()
a.StartTime = New DateTime(2010, 1, 1)
a.EndTime = New DateTime(2010, 1, 2)
a.HeaderText = "a"
calendar.Schedule.Items.Add(a)

Dim b As New Appointment()
b.StartTime = New DateTime(2010, 1, 3)
b.EndTime = New DateTime(2010, 1, 4)
b.HeaderText = "b"
calendar.Schedule.Items.Add(b)

Specify a custom brush for the text of both items.

C#  Copy Code

CalendarStyle style = new CalendarStyle();
style.Foreground = Brushes.Orange;
calendar.ItemSettings.CalendarStyle = style;

Visual Basic  Copy Code

Dim style As New CalendarStyle()
style.Foreground = Brushes.Orange
calendar.ItemSettings.CalendarStyle = style

Running the code at this point will display both items with text colored in Orange. It is also noticeable that the rest of the visualization properties are not modified since they were not set explicitly in the custom style and are therefore obtained from the current theme.

Now define a custom background for item a using the following code:

C#  Copy Code

CalendarStyle aStyle = new CalendarStyle();
aStyle.Background = Brushes.Blue;
calendar.SetItemStyle(a, aStyle);

Visual Basic  Copy Code

Dim aStyle As New CalendarStyle()
aStyle.Background = Brushes.Blue
calendar.SetItemStyle(a, aStyle)

The code above will change the background of a, while the background of b will be left intact.