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"> |
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"> |
By default, the CellPresenter is initialized with the above styles as follows:
C# Copy Code |
---|
StyleKeySimple = "SimpleCellStyle"; |
Visual Basic Copy Code |
---|
StyleKeySimple = "SimpleCellStyle" |
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) => |
For more information on how to create new templates, check the DualView sample.