WPF – Resource not loading from Generic.xaml

custom-controlsgeneric.xamlresourcedictionarywpf

Themes\Generic.xaml:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="WPF Commons;component/Controls/Layout/Foo/FooItem.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

Controls\Layout\Foo\FooItem.xaml:

<Style TargetType="{x:Type l:FooItem}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type l:FooItem}">
                <Border>
                    <ContentPresenter ContentSource="Header" />
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>


If I copy the entire style into my usercontrol resources it works fine. But, if I don't, the usercontrol shows up empty. In Expression Blend 4, I right-clicked and chose Edit Template>, but it won't let me select Edit a Copy... which leads me to believe that something is severely wrong and the Generic.xaml isn't loading properly. I figure it's Generic.xaml because if I remove the MergedDictionary call and copy/paste the xaml style directly into Generic.xaml it still doesn't work.

Best Answer

I'm gonna take a wild guess that you altered your AssemblyInfo.cs file and either changed (or removed) the following line:

[assembly: ThemeInfo(
    ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
    //(used if a resource is not found in the page, 
    // or application resource dictionaries)
    ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
    //(used if a resource is not found in the page, 
    // app, or any theme specific resource dictionaries)
)]

You need to tell your assembly about your ThemeInfo. :)

Related Topic