MindFusion.Wpf Pack Programmer's Guide
Creating New Item Template

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

XAML  Copy Code

<Style TargetType="{x:Type planner:ItemPresenter}">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type planner:ItemPresenter}">
      ...
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

The style definition needs to be placed in the application's resources (App.xaml or Application.xaml).

More advanced scenarios can include several triggers, which supply different templates depending on specific conditions. The Default Item Template uses this technique to provide different templates for the items in different views. Below is an example XAML code illustrating this.

XAML  Copy Code

<Style TargetType="{x:Type local:ItemPresenter}">
  <Style.Triggers>
    <DataTrigger Binding="{Binding StyleKey, RelativeSource={RelativeSource Self}}" Value="Complex">
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type local:ItemPresenter}">

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

          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </DataTrigger>
    <DataTrigger Binding="{Binding StyleKey, RelativeSource={RelativeSource Self}}" Value="Simple">
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type local:ItemPresenter}">

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

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

For more information on how to create new templates, check Tutorial 5: Custom Item Templates.