DotNetBar WPF Schedule control allows you to set per Appointment style for the views that are created to represent that Appointment in User Interface.

The style you want to use should be included in your application or window resources and use ComponentResourceKey as x:Key. Then you assign the same key to Appointment.StyleResourceName property.

So here is how that would look like (this fits into our Schedule Control sample included with DotNetBar for WPF installation):

1. You define your custom style as such (notice ComponentResourceKey):

<r:AdvWindow.Resources>
  <s:DateTimePartConverter x:Key="DateConverter" />
  <Style TargetType="{x:Type s:AppointmentView}" x:Key="{ComponentResourceKey TypeInTargetAssembly=local:Window1, ResourceId=AppView}">
    <Setter Property="BorderBrush" Value="Red" />
    <Setter Property="Background" Value="White" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="CornerRadius" Value="0" />
    <Setter Property="FontSize" Value="10.5" />
    <Style.Triggers>
      <Trigger Property="s:CalendarView.ParentView" Value="Week">
        <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly=local:Window1, ResourceId=WeekView}}" />
      </Trigger>
      <Trigger Property="s:CalendarView.ParentView" Value="Month">
        <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly=local:Window1, ResourceId=MonthView}}" />
      </Trigger>
    </Style.Triggers>
  </Style>
 
  <!-- Appointment Month View -->
  <ControlTemplate TargetType="{x:Type s:AppointmentView}" x:Key="{ComponentResourceKey {x:Type s:AppointmentView}, MonthView}">
    <Border Background="{TemplateBinding Background}"
         BorderBrush="{TemplateBinding BorderBrush}"
         BorderThickness="{TemplateBinding BorderThickness}"
         CornerRadius="{TemplateBinding CornerRadius}">
      <Grid>
        <Border BorderThickness="1" CornerRadius="{TemplateBinding CornerRadius}">
          <Border.BorderBrush>
            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
              <GradientStop Color="#90FFFFFF" Offset="0" />
              <GradientStop Color="Transparent" Offset=".4" />
              <GradientStop Color="Transparent" Offset="1" />
            </LinearGradientBrush>
          </Border.BorderBrush>
        </Border>
        <DockPanel LastChildFill="True">
          <TextBlock
           Margin="2"
           Text="{Binding Path=StartTime, Converter={StaticResource DateConverter},  ConverterParameter=ShortTime, RelativeSource={RelativeSource TemplatedParent}}"
           DockPanel.Dock="Left"
           TextWrapping="NoWrap"
           TextTrimming="None"
           HorizontalAlignment="Left"
           VerticalAlignment="Top"
           Padding="0"
           TextAlignment="Left"
           SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"
           Name="PART_StartTime"
           Opacity=".7"/>
          <TextBlock
           TextWrapping="NoWrap"
           TextTrimming="CharacterEllipsis"
           Name ="PART_Subject"
           Padding="0"
           Margin="2"
           HorizontalAlignment="Stretch"
           VerticalAlignment="Top"
           TextAlignment="Left"
           Text="{TemplateBinding Subject}"
           SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
        </DockPanel>
      </Grid>
    </Border>
    <ControlTemplate.Triggers>
      <Trigger Property="IsAllDayEvent" Value="True">
        <Setter Property="Visibility" Value="Collapsed" TargetName="PART_StartTime" />
        <Setter Property="FontWeight" Value="Bold" />
      </Trigger>
      <MultiTrigger>
        <MultiTrigger.Conditions>
          <Condition Property="StartTimeInView" Value="False" />
          <Condition Property="EndTimeInView" Value="True" />
        </MultiTrigger.Conditions>
        <MultiTrigger.Setters>
          <Setter Property="CornerRadius" Value="0,5,5,0" />
        </MultiTrigger.Setters>
      </MultiTrigger>
      <MultiTrigger>
        <MultiTrigger.Conditions>
          <Condition Property="StartTimeInView" Value="True" />
          <Condition Property="EndTimeInView" Value="False" />
        </MultiTrigger.Conditions>
        <MultiTrigger.Setters>
          <Setter Property="CornerRadius" Value="5,0,0,5" />
        </MultiTrigger.Setters>
      </MultiTrigger>
      <MultiTrigger>
        <MultiTrigger.Conditions>
          <Condition Property="StartTimeInView" Value="False" />
          <Condition Property="EndTimeInView" Value="False" />
        </MultiTrigger.Conditions>
        <MultiTrigger.Setters>
          <Setter Property="CornerRadius" Value="0" />
        </MultiTrigger.Setters>
      </MultiTrigger>
    </ControlTemplate.Triggers>
  </ControlTemplate>
 
  <!-- Appointment Week View -->
  <ControlTemplate TargetType="{x:Type s:AppointmentView}" x:Key="{ComponentResourceKey {x:Type s:AppointmentView}, WeekView}">
    <Border Background="{TemplateBinding Background}"
         BorderBrush="{TemplateBinding BorderBrush}"
         BorderThickness="{TemplateBinding BorderThickness}"
         CornerRadius="{TemplateBinding CornerRadius}">
      <Grid>
        <Border BorderThickness="1" CornerRadius="{TemplateBinding CornerRadius}">
          <Border.BorderBrush>
            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
              <GradientStop Color="#90FFFFFF" Offset="0" />
              <GradientStop Color="Transparent" Offset=".4" />
              <GradientStop Color="Transparent" Offset="1" />
            </LinearGradientBrush>
          </Border.BorderBrush>
        </Border>
        <DockPanel LastChildFill="True">
          <Border Width="5" CornerRadius="{TemplateBinding TimeSideMarkerCornerRadius}" DockPanel.Dock="Left" Background="{TemplateBinding TimeSideMarkerBackground}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0,0,1,1" Height="{TemplateBinding DurationHeight}" Name="DurationMarker" VerticalAlignment="Top" />
          <StackPanel Orientation="Vertical" Margin="1">
            <TextBlock
             TextWrapping="Wrap"
             TextTrimming="CharacterEllipsis"
             Name ="PART_Subject"
             Padding="0"
             Margin="2"
             HorizontalAlignment="Stretch"
             VerticalAlignment="Top"
             TextAlignment="Left"
             Text="{TemplateBinding Subject}"
             SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
           <TextBlock
             TextWrapping="Wrap"
             Name ="PART_Description"
             Padding="0"
             Margin="2"
             HorizontalAlignment="Stretch"
             VerticalAlignment="Top"
             TextAlignment="Left"
             Text="{TemplateBinding Description}"
             SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
          </StackPanel>
        </DockPanel>
      </Grid>
    </Border>
    <ControlTemplate.Triggers>
      <Trigger Property="DurationHeight" Value="NaN">
        <Setter Property="BorderThickness" Value="0,0,1,0" TargetName="DurationMarker" />
        <Setter Property="VerticalAlignment" Value="Stretch" TargetName="DurationMarker" />
      </Trigger>
      <Trigger Property="TimeSideMarkerBackground" Value="{x:Null}">
        <Setter Property="Visibility" Value="Collapsed" TargetName="DurationMarker" />
      </Trigger>
      <Trigger Property="IsAllDayEvent" Value="True">
        <Setter Property="Visibility" Value="Collapsed" TargetName="PART_Description" />
        <Setter Property="Visibility" Value="Collapsed" TargetName="DurationMarker" />
        <Setter Property="TextWrapping" Value="NoWrap" TargetName="PART_Subject" />
      </Trigger>
    </ControlTemplate.Triggers>
  </ControlTemplate>
</r:AdvWindow.Resources>

2. When you create new Appointment you set StyleResourceName property as such:

C#

Appointment appointment = new Appointment();
 
appointment.StyleResourceName = new ComponentResourceKey(typeof(Window1), "AppView");
 
appointment.Subject = "Appointment with Custom Style";
appointment.StartTime = DateTime.Today.AddHours(9);
appointment.EndTime = appointment.StartTime.AddHours(1);
appointment.TimeMarkedAs = Appointment.TimerMarkerOutOfOffice;
 
// Add appointment to the model
 
_Model.Appointments.Add(appointment);

VB

Dim appointment As New Appointment()
 
appointment.StyleResourceName = New ComponentResourceKey(GetType(Window1), "AppView")
 
appointment.Subject = "Appointment with Custom Style"
appointment.StartTime = DateTime.Today.AddHours(9)
appointment.EndTime = appointment.StartTime.AddHours(1)
appointment.TimeMarkedAs = Appointment.TimerMarkerOutOfOffice
 
' Add appointment to the model

_Model.Appointments.Add(appointment)

In case that you want to use Appointment.Tag property for changing the AppointmentView style you cannot use Appointment.Tag directly in your trigger since triggers require dependency properties and Appointment.Tag is simple object property. In that case you can bind AppointmentView.Tag to Appointment.Tag and then key off of that. Here is small example that illustrates this concept:

<Style TargetType="s:AppointmentView">
    <Setter Property="Tag" Value="{Binding Path=Appointment.Tag, RelativeSource={RelativeSource Self}}" />
    <Style.Triggers>
        <Trigger Property="Tag" Value="E">
            <Setter Property="Background" Value="Red" />
        </Trigger>
    </Style.Triggers>
</Style>

.

Related posts:

  1. How to Assign Context Menu to Appointment View
  2. WPF Schedule Quick Start Guide
  3. How to use marked dates and custom styles in DotNetBar for WPF MonthCalendar
  4. How to build Office 2010 style Backstage application menu with DotNetBar for WPF
  5. How to customize WPF Office 2007 Color Schemes