MindFusion.Scheduling for Silverlight Programmer's Guide
Creating New Cell Template

New cell templates are created the same way as custom control templates - by creating a new .NET Style with TargetType set to CellPresenter. The Style should provide a setter for the Template property. The following XAML snippet illustrates how.

XAML  Copy Code

<Style TargetType="planner:CellPresenter" x:Key="MyStyle">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="planner:CellPresenter">
      ...
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

The style definition needs to be placed in the application's resources (App.xaml or Application.xaml). The style needs to specify a Key which should be subsequently used to assign the style to the CellPresenter through one of its properties - StyleKeySimple, StyleKeyWithHeader and StyleKeyToday. The Default Cell Template uses this technique to provide different templates for the cells in different views. Below is an example XAML code illustrating this.

XAML  Copy Code

<Style TargetType="local:CellPresenter" x:Key="SimpleCellStyle">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="local:CellPresenter">

        <!-- The template for Timetable and Resource view cells goes here -->

      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

<Style TargetType="local:CellPresenter" x:Key="TodayCellStyle">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="local:CellPresenter">

        <!-- The template for the cell representing the current day goes here -->

      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

<Style TargetType="local:CellPresenter" x:Key="WithHeaderCellStyle">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="local:CellPresenter">

        <!-- The template for SingleMonth, MonthRange, List and WeekRange view cells goes here -->

      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

By default, the CellPresenter is initialized with the above styles as follows:

C#  Copy Code

StyleKeySimple = "SimpleCellStyle";
StyleKeyToday = "TodayCellStyle";
StyleKeyWithHeader = "WithHeaderCellStyle";

Visual Basic  Copy Code

StyleKeySimple = "SimpleCellStyle"
StyleKeyToday = "TodayCellStyle"
StyleKeyWithHeader = "WithHeaderCellStyle"

When you define one or more new styles for the presenter you need to assign their keys to the corresponding properties. A common way to do this is by handling the CellPresenterCreated event of the Calendar class. The following code illustrates how to assign a custom style (MyStyle) to newly created presenters:

C#  Copy Code

calendar.CellPresenterCreated += (sender, e) =>
    {
        e.CellPresenter.StyleKeySimple = "MyStyle";
        e.CellPresenter.StyleKeyToday = "MyStyle";
        e.CellPresenter.StyleKeyWithHeader = "MyStyle";
    };

For more information on how to create new templates, check the DualView sample.