ComponentOne Scheduler for WPF: Using the Calendar Controls > Using Calendar Themes > Setting the Calendar Theme

Setting the Calendar Theme

All calendar controls use the current system theme, by default. If you want to use a different theme, there are several ways to select a new one.

To set the theme at design time in Visual Studio:

1.   Right-click the control.

2.   Select Theme and choose one of the fourteen predefined themes.

Note: You can also change the theme through the Properties window by selecting the option from the drop-down list next to the Theme property.

To set the theme in Microsoft Blend, change the Theme property at design time:

1.   Select the C1MonthCalendar control in your XAML window or page.

2.   In the Properties panel, under Appearance, click the drop-down arrow next to the Theme property and choose one of the predefined themes.

To set the theme using the ResourceID, use the following XAML:

       <my:C1MonthCalendar x:Name="calendar1" MaxSelectionCount="14"

Theme="{DynamicResource {ComponentResourceKey

TypeInTargetAssembly=my:C1CalendarBase, ResourceId= Luna.Metallic}}"/>

To set the theme using C1CalendarResources static fields, add the following code to your project:

      Visual Basic

calendar.Theme = C1CalendarResources.Royale

      C#

calendar.Theme = C1CalendarResources.Royale;

To set the theme by defining a ResourceDictionary and DefaultThemeKey in your Page, Window, or Application resources:

       <Page.Resources>

             <ResourceDictionary>

<ResourceDictionary x:Key="{x:Static my:C1CalendarBase.DefaultThemeKey}"

Source="/C1.WPF.C1Schedule;component/themes/CalendarThemes/Aero/Aero.xaml" />

             </ResourceDictionary.MergedDictionaries>

       </Page.Resources>

Note that this will affect all controls in the current scope.

You can also create your own theme ResourceDictionaries and use them with the calendar controls.

The best way to customize one of the predefined themes is to include the default theme definition in a custom ResourceDictionary and redefine necessary resources, such as theme brushes, there.

Note: To ensure all default styles and templates continue to work correctly during customization, it is suggested that the resource keys are not changed from their default settings.

The following XAML example shows how to use a custom calendar theme:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:my="clr-namespace:C1.WPF.C1Schedule;assembly=C1.WPF.C1Schedule"

x:Class="TestControls.DefaultCalendarWindow"

Title="DefaultCalendarWindow">

       <Window.Resources>

             <ResourceDictionary>

                    <ResourceDictionary x:Key="theme">

                           <ResourceDictionary.MergedDictionaries>

                                  <ResourceDictionary

       Source="/C1.WPF.C1Schedule;component/themes/CalendarThemes/Luna/HomeStead.xaml" />

                           </ResourceDictionary.MergedDictionaries>

                           <SolidColorBrush x:Key="C1Calendar_NavArrowBrush" Color="Green" />

                           <SolidColorBrush x:Key="C1Calendar_WeekendTextBrush" Color="Green" />

                           <Style TargetType="{x:Type my:C1MonthCalendar}"

                                  BasedOn="{StaticResource {ComponentResourceKey

TypeInTargetAssembly={x:Type my:C1MonthCalendar},

                           ResourceId=BaseMonthCalendarStyle}}">

                                  <Setter Property="Background" Value="Yellow"/>

                           </Style>

                    </ResourceDictionary>

             </ResourceDictionary>

       </Window.Resources>

       <Grid >

       <my:C1MonthCalendar x:Name="calendar1" MaxSelectionCount="14" SnapsToDevicePixels="true"

                           Theme="{DynamicResource theme}"/>

       </Grid>

  </Window>


Send comments about this topic to ComponentOne.
Copyright © 1987-2010 ComponentOne LLC. All rights reserved.