Xceed Pro Themes for WPF v3.0 Documentation
Applying Themes Implicitly
Welcome to Xceed Pro Themes for WPF v3.0 > Basic Concepts > Applying Themes Implicitly

Applying one of Xceed's themes to your current application can literally take only a couple of lines of XAML code and less than two minutes of your time, thanks to the product's support of implicit styles. This is the default behavior of Xceed's themes.

If you do not want the themes to override your own styles and brushes—in order to selectively apply our styles or brushes, for example—you must set StyleUsageMode of the theme resource dictionary to Explicit. (For details, see Applying Themes Explicitly.)

Once you have added the references to the required assemblies to your project and declared the namespace maps that are to be used with the xmlns attribute (see Adding Xceed's Themes to Your Current Project), simply add the resource dictionary to the resources of the object you wish to style.

XAML
Copy Code
<Application.Resources>

    <xcpt:GlassResourceDictionary LicenseKey="XXXXX-XXXXX-XXXXX-XXXX" />

</Application.Resources>

Note that in order to use one of Xceed's themes, you must license it at this point. If the same type of ThemeResourceDictionary-derived resource theme is to be used more than once, the LicenseKey may be omitted subsequently. However, you must be sure to license the first theme resource dictionary that is loaded.

If additional resources must be added to the same location as the theme resource dictionary, the ResourceDictionary.MergedDictionaries property must be used:

XAML
Copy Code
<Window x:Class="WpfApplication1.Window1"

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

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

        xmlns:xcpt="http://schemas.xceed.com/wpf/xaml/themes"

        Title="Window1">

  <Window.Resources>

      <ResourceDictionary>

        <ResourceDictionary.MergedDictionaries>

            <xcpt:GlassResourceDictionary LicenseKey="XXXXX-XXXXX-XXXXX-XXXX" />

        </ResourceDictionary.MergedDictionaries>

        ... [Other resources]

      </ResourceDictionary>

  </Window.Resources>

  ...

Adding something to a theme resource dictionary will have absolutely no effect, and no error or exception will occur.

XAML
Copy Code
<ResourceDictionary>

  <ResourceDictionary.MergedDictionaries>

      <xcpt:MediaResourceDictionary>

        <Style TargetType="SomeControl">

            <Setter Property="Background"

                    Value="Black" />

        </Style>

        ...

Using Implicit Styles without Losing Your Chosen Theme

It is common to specify an implicit style for a control to avoid having to repeatedly set properties in each instance of that control. For example:

XAML
Copy Code
<Window.Resources>

  <Style TargetType="Button">

    <Setter Property="Margin" Value="5" />

  </Style>

</Window.Resources>

However, doing this means that the buttons in this Window will not be styled according to the chosen theme. This is because the implicit style specifying the Margin overrides the Button style of the theme. This problem can be overcome by using the BasedOn property.

XAML
Copy Code
<Window.Resources>

  <ResourceDictionary>

      <ResourceDictionary.MergedDictionaries>

        <xcpt:MediaResourceDictionary LicenseKey="XXXXX-XXXXX-XXXXX-XXXX" />

      </ResourceDictionary.MergedDictionaries>

      <!-- Must specify BasedOn to style the Button as Media. -->

      <Style TargetType="Button"

            BasedOn="{x:Static xcpt:MediaResources.ButtonStyle}">

        <Setter Property="Margin" Value="5" />

      </Style>

  </ResourceDictionary>

</Window.Resources>