Why doesn't ThemeDictionary fall back to Themes\Generic.xaml? RRS feed

  • Question

  • We have a WPF 3.5 SP1 application that uses the ThemeDictionary markup extension. Recently, we have noticed that ThemeDictionary does not automatically default to Themes\Generic.xaml if there is no theme file for the currently selected theme. Is this a bug in WPF 3.5 SP1, and is there any workaround?

    Here is an example for reproducing this behavior:

    XAML file for window in main application:

    <Window x:Class="ThemeTest.Window1"
      Title="Window1" Height="300" Width="300">
            <ResourceDictionary Source="{ThemeDictionary MyCustomControl}"/>
        <TextBlock Foreground="{StaticResource MyColor}">This is a test</TextBlock>

    Themes\Generic.xaml file for custom control DLL named "MyCustomControl.dll":

      <SolidColorBrush x:Key="MyColor" Color="Red"/>
      <Style TargetType="{x:Type local:CustomControl1}">
        <Setter Property="Template">
            <ControlTemplate TargetType="{x:Type local:CustomControl1}">
              <Border Background="{TemplateBinding Background}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}">

    When starting the main application, the following exception occurs:

      System.Windows.Markup.XamlParseException occurred
      'System.Windows.ThemeDictionaryExtension' value cannot be assigned to property 'Source' of object 'System.Windows.ResourceDictionary'. Cannot locate resource 'themes/luna.metallic.xaml'.  Error at object 'System.Windows.ThemeDictionaryExtension' in markup file 'ThemeTest;component/window1.xaml' Line 8 Position 37.

    - Frank

    Tuesday, June 28, 2011 8:18 AM


  • Hi Frank,

    I can reproduce this problem in 3.5SP1 and the problem seems to be fixed in 4.0.

    I suggest you to create a resource file for each theme and merge generic.xaml to each theme specific resoruce dicionary to resolve this issue.

    For example,

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      <ResourceDictionary Source="pack://application:,,,/WpfApplication1;component/Themes/Generic.xaml"/>

    Best regards,

    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by fmunkert Wednesday, June 29, 2011 8:12 AM
    Wednesday, June 29, 2011 8:05 AM