MindFusion.Scheduling for Silverlight Programmer's Guide
The Default Item Template

Below is the complete XAML code of the default styles of the item presenter.

XAML  Copy Code

<Style TargetType="local:ItemPresenter" x:Key="ComplexItemStyle">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="local:ItemPresenter">
        <local:ResizeBands
          Orientation="{TemplateBinding Orientation}"
          DataContext="{Binding Path=., RelativeSource={RelativeSource TemplatedParent}}"
          ItemSettings="{TemplateBinding ItemSettings}"
          ResizeBandsVisible="{TemplateBinding Selected}">
          <local:SideBorders>
            <Border Background="{Binding ItemStyle.Background}">
              <Grid>
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="Auto" />
                  <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <StackPanel Orientation="Vertical">
                  <Image Source="/MindFusion.Scheduling.Silverlight;component/Resources/Recurrence.png"
                    Visibility="{Binding RecurrenceIconVisibility}" Margin="1" />
                  <Image Source="/MindFusion.Scheduling.Silverlight;component/Resources/RecurrenceEx.png"
                    Visibility="{Binding RecurrenceExceptionIconVisibility}" Margin="1" />
                  <Image Source="/MindFusion.Scheduling.Silverlight;component/Resources/Reminder.png"
                    Visibility="{Binding ReminderIconVisibility}" Margin="1" />
                </StackPanel>
                <StackPanel Grid.Column="1" Orientation="Vertical">
                  <Border
                    BorderBrush="{Binding ItemStyle.LineBrush}"
                    BorderThickness="0,0,0,1"
                    Height="{Binding ItemSettings.HeaderSize}"
                    Margin="6,0,6,0">
                    <TextBlock x:Name="HeaderBlock"
                      TextWrapping="Wrap"
                      Text="{Binding Item.HeaderText, RelativeSource={RelativeSource TemplatedParent}}"
                      DataContext="{TemplateBinding ItemStyle}"
                      Foreground="{Binding Foreground}"
                      TextAlignment="{Binding TextAlignment}"
                      VerticalAlignment="{Binding VerticalAlignment}"
                      FontFamily="{Binding FontFamily}"
                      FontSize="{Binding FontSize}"
                      FontStretch="{Binding FontStretch}"
                      FontStyle="{Binding FontStyle}"
                      FontWeight="{Binding FontWeight}" />
                  </Border>
                  <TextBlock
                    DataContext="{TemplateBinding Item}"
                    TextWrapping="Wrap" Text="{Binding DescriptionText}"
                    Margin="5,1,1,1" Grid.Column="1" Grid.Row="1" />
                </StackPanel>
              </Grid>
            </Border>
          </local:SideBorders>
        </local:ResizeBands>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

<Style TargetType="local:ItemPresenter" x:Key="SimpleItemHorizontalStyle">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="local:ItemPresenter">
        <Grid
          DataContext="{Binding Path=., RelativeSource={RelativeSource TemplatedParent}}"
          Background="{Binding ItemStyle.Background}">
          <local:SideBorders>
            <Grid>
              <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
              </Grid.ColumnDefinitions>
              <Image Grid.Column="0"
                Visibility="{TemplateBinding StartArrowImageVisibility}"
                HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="None" Margin="1"
                Source="/MindFusion.Scheduling.Silverlight;component/Resources/ArrowLeft.png" />
              <StackPanel Orientation="Horizontal" Grid.Column="1">
                <Image Source="/MindFusion.Scheduling.Silverlight;component/Resources/Recurrence.png"
                  Visibility="{Binding RecurrenceIconVisibility}" Stretch="None" Margin="1" />
                <Image Source="/MindFusion.Scheduling.Silverlight;component/Resources/RecurrenceEx.png"
                  Visibility="{Binding RecurrenceExceptionIconVisibility}" Stretch="None" Margin="1" />
                <Image Source="/MindFusion.Scheduling.Silverlight;component/Resources/Reminder.png"
                  Visibility="{Binding ReminderIconVisibility}" Stretch="None" Margin="1" />
              </StackPanel>
              <TextBlock x:Name="HeaderBlock" Grid.Column="2"
                TextWrapping="Wrap"
                Text="{Binding Item.HeaderText, RelativeSource={RelativeSource TemplatedParent}}"
                DataContext="{TemplateBinding ItemStyle}"
                Foreground="{Binding Foreground}"
                TextAlignment="{Binding TextAlignment}"
                VerticalAlignment="{Binding VerticalAlignment}"
                FontFamily="{Binding FontFamily}"
                FontSize="{Binding FontSize}"
                FontStretch="{Binding FontStretch}"
                FontStyle="{Binding FontStyle}"
                FontWeight="{Binding FontWeight}" />
              <Image Grid.Column="3"
                Visibility="{TemplateBinding EndArrowImageVisibility}"
                HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="None" Margin="1"
                Source="/MindFusion.Scheduling.Silverlight;component/Resources/ArrowRight.png" />
            </Grid>
          </local:SideBorders>
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

<Style TargetType="local:ItemPresenter" x:Key="SimpleItemVerticalStyle">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="local:ItemPresenter">
        <Grid
          DataContext="{Binding Path=., RelativeSource={RelativeSource TemplatedParent}}"
          Background="{Binding ItemStyle.Background}">
          <local:SideBorders>
            <Grid>
              <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition />
                <RowDefinition Height="Auto" />
              </Grid.RowDefinitions>
              <Image Grid.Row="0"
                Visibility="{TemplateBinding StartArrowImageVisibility}"
                HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="None" Margin="1"
                Source="/MindFusion.Scheduling.Silverlight;component/Resources/ArrowUp.png" />
              <StackPanel Orientation="Vertical" Grid.Row="1">
                <Image Source="/MindFusion.Scheduling.Silverlight;component/Resources/Recurrence.png"
                  Visibility="{Binding RecurrenceIconVisibility}" Stretch="None" Margin="1" />
                <Image Source="/MindFusion.Scheduling.Silverlight;component/Resources/RecurrenceEx.png"
                  Visibility="{Binding RecurrenceExceptionIconVisibility}" Stretch="None" Margin="1" />
                <Image Source="/MindFusion.Scheduling.Silverlight;component/Resources/Reminder.png"
                  Visibility="{Binding ReminderIconVisibility}" Stretch="None" Margin="1" />
              </StackPanel>
              <TextBlock Grid.Row="2"
                TextWrapping="Wrap"
                Text="{Binding Item.HeaderText, RelativeSource={RelativeSource TemplatedParent}}"
                DataContext="{TemplateBinding ItemStyle}"
                Foreground="{Binding Foreground}"
                TextAlignment="{Binding TextAlignment}"
                VerticalAlignment="{Binding VerticalAlignment}"
                FontFamily="{Binding FontFamily}"
                FontSize="{Binding FontSize}"
                FontStretch="{Binding FontStretch}"
                FontStyle="{Binding FontStyle}"
                FontWeight="{Binding FontWeight}" /> 
              <Image Grid.Row="3"
                Visibility="{TemplateBinding EndArrowImageVisibility}"
                HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="None" Margin="1"
                Source="/MindFusion.Scheduling.Silverlight;component/Resources/ArrowDown.png" />
            </Grid>
          </local:SideBorders>
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

<Style TargetType="local:SideBorders">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="local:SideBorders">
        <Grid>
          <Rectangle HorizontalAlignment="Left"
            Width="{Binding BorderThickness.Left}"
            Fill="{Binding ItemStyle.LeftBorderBrush}" />
          <Rectangle VerticalAlignment="Top"
            Height="{Binding BorderThickness.Top}"
            Fill="{Binding ItemStyle.TopBorderBrush}" />
          <Rectangle HorizontalAlignment="Right"
            Width="{Binding BorderThickness.Right}"
            Fill="{Binding ItemStyle.RightBorderBrush}" />
          <Rectangle VerticalAlignment="Bottom"
            Height="{Binding BorderThickness.Bottom}"
            Fill="{Binding ItemStyle.BottomBorderBrush}" />
          <Border BorderThickness="{Binding BorderThickness}">
            <ContentPresenter Margin="{Binding ItemStyle.ContentMargin}" />
          </Border>
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

<Style TargetType="local:ResizeBands" x:Key="ResizeBandsVertical">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="local:ResizeBands">
        <Grid>
          <Grid.Resources>
            <local:VisibleConverter x:Key="visibleConverter"/>
          </Grid.Resources>
          <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition />
            <RowDefinition Height="Auto"/>
          </Grid.RowDefinitions>
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition />
          </Grid.ColumnDefinitions>
          <Border
            Grid.ColumnSpan="2"
            BorderThickness="1,1,1,0"
            IsHitTestVisible="False"
            Background="Transparent"
            BorderBrush="Transparent"
            Height="{Binding ItemSettings.ResizeBandSize}" />
          <Border
            Grid.ColumnSpan="2"
            BorderThickness="1,1,1,0"
            Background="{Binding ItemStyle.FillBrush}"
            BorderBrush="{Binding ItemStyle.BorderBrush}"
            Height="{Binding ItemSettings.ResizeBandSize}"
            Visibility="{Binding ResizeBandsVisible, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource visibleConverter}}" />
          <Border Grid.Row="1"
            BorderThickness="1,1,0,1"
            Width="{Binding ItemSettings.MoveBandSize}"
            Background="{Binding ItemStyle.FillBrush}"
            BorderBrush="{Binding ItemStyle.BorderBrush}" />
          <Border
            Grid.Row="2" Grid.ColumnSpan="2"
            BorderThickness="1,0,1,1"
            IsHitTestVisible="False"
            Background="Transparent"
            BorderBrush="Transparent"
            Height="{Binding ItemSettings.ResizeBandSize}" />
          <Border
            Grid.Row="2" Grid.ColumnSpan="2"
            BorderThickness="1,0,1,1"
            Background="{Binding ItemStyle.FillBrush}"
            BorderBrush="{Binding ItemStyle.BorderBrush}"
            Height="{Binding ItemSettings.ResizeBandSize}"
            Visibility="{Binding ResizeBandsVisible, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource visibleConverter}}" />
          <ContentPresenter Grid.Column="1" Grid.Row="1" />
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

<Style TargetType="local:ResizeBands" x:Key="ResizeBandsHorizontal">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="local:ResizeBands">
        <Grid>
          <Grid.Resources>
            <local:VisibleConverter x:Key="visibleConverter"/>
          </Grid.Resources>
          <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
          </Grid.RowDefinitions>
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
            <ColumnDefinition Width="Auto" />
          </Grid.ColumnDefinitions>
          <Border
            Grid.RowSpan="2"
            BorderThickness="1,1,0,1"
            IsHitTestVisible="False"
            Background="Transparent"
            BorderBrush="Transparent"
            Width="{Binding ItemSettings.ResizeBandSize}" />
          <Border
            Grid.RowSpan="2"
            BorderThickness="1,1,0,1"
            Width="{Binding ItemSettings.ResizeBandSize}"
            Background="{Binding ItemStyle.FillBrush}"
            BorderBrush="{Binding ItemStyle.BorderBrush}"
            Visibility="{Binding ResizeBandsVisible, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource visibleConverter}}" />
          <Border
            Grid.Column="1"
            BorderThickness="1,1,1,0"
            Background="{Binding ItemStyle.FillBrush}"
            BorderBrush="{Binding ItemStyle.BorderBrush}"
            Height="{Binding ItemSettings.MoveBandSize}" />
          <Border
            Grid.Column="2" Grid.RowSpan="2"
            BorderThickness="0,1,1,1"
            IsHitTestVisible="False"
            Background="Transparent"
            BorderBrush="Transparent"
            Width="{Binding ItemSettings.ResizeBandSize}" />
          <Border
            Grid.Column="2" Grid.RowSpan="2"
            BorderThickness="0,1,1,1"
            Width="{Binding ItemSettings.ResizeBandSize}"
            Background="{Binding ItemStyle.FillBrush}"
            BorderBrush="{Binding ItemStyle.BorderBrush}"
            Visibility="{Binding ResizeBandsVisible, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource visibleConverter}}" />
          <ContentPresenter Grid.Column="1" Grid.Row="1"/>
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

The local namespace is defined as follows:

XAML  Copy Code

xmlns:local="clr-namespace:MindFusion.Scheduling.Silverlight;assembly=MindFusion.Scheduling.Silverlight"

As can be seen in the above XAML, there are several styles which supply a control template for the items in different contexts. For example, the ComplexItemStyle supplies the template of the so-called complex items. Those are the items in Resource view and non all day items in Timetable view. The next style - SimpleItemHorizontalStyle - supplies the template of the so-called simple items when they are displayed horizontally. Simple items are all day items in Timetable view and the items in SingleMonth, MonthRange, List and WeekRange views. The last style - SimpleItemVerticalStyle - supplies the template for simple items, displayed vertically.

The following table illustrates the presentation of the same item in the three different contexts:

Condition

Presentation

Style=ComplexItemStyle

Style=SimpleItemHorizontalStyle

Style=SimpleItemVerticalStyle

The keys of the individual styles are assigned to the respective ItemPresenter properties - StyleKeyComplex, StyleKeySimpleHorizontal and StyleKeySimpleVertical. It is completely legal to assign the same style for the three cases.

Named Elements

There is one element of particular interest in the template - HeaderBlock. This element is used when initiating item in-place editing operations in order to determine where the in-place text box should be opened. If you create a custom template and want to retain the in-place editing functionality you need to name an element HeaderBlock. Additionally you need to place this element in either grid or border parent.