1

I have a small program that has a converter for the background color of an item based on a boolean value. I also have a Style Sheet to cover a lot of the basic formatting. I have both of these working independently, but when I try to out them together as in:

UserControl.Resources>
    <converter:RawMaterialHighlight x:Key="RawMat"></converter:RawMaterialHighlight>
    <ResourceDictionary Source="../Styles.xaml"></ResourceDictionary>
</UserControl.Resources>

I get an 2 errors:

Each dictionary entry must have an associated key.

All objects added to an IDictionary must have a Key attribute or some other type of key associated with them. Line 13 Position 10.

When I add x:Key"Dictionary" to the dictionary line, it says that it cannot resolve the dictionary resource

<TextBlock Text="Material Type" Style="{StaticResource ResourceKey=TextBlockSectionHeader}"></TextBlock>

The resource "TextBlockSectionHeader" could not be resolved.

if I add Dict.TextBlockSectionHeader I get the same 'could not be resolved' error. I am assuming that I am declaring it incorrectly in the Resources section, I have so far been unable to find the solution though.

Community
  • 1
  • 1
Steven Deam
  • 567
  • 1
  • 7
  • 21

1 Answers1

3

I found the answer here: Merged dictionaries and local resources

the answer was to nest the style in a merged dictionary and put the whole thing inside a resource dictionary:

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>                
            <ResourceDictionary Source="../Styles.xaml"></ResourceDictionary>
        </ResourceDictionary.MergedDictionaries>
        <converter:RawMaterialHighlight x:Key="RawMat"></converter:RawMaterialHighlight>
    </ResourceDictionary>        
</UserControl.Resources>
Steven Deam
  • 567
  • 1
  • 7
  • 21