views:

221

answers:

1

Ok, that question was really hard to ask in one line. Here's the deal. If I have this XAML:

<ResourceDictionary
  x:Class="MyAssembly.MiscResources"    
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;

    <SolidColorBrush x:Key="MyBrush" Color="Purple" />    

</ResourceDictionary>

Then I have this in some C#:

var dict = new MiscResources();

dict gets created and seems to function normally, but it has 0 elements. Not that this is some kind of neccessary behavior, but I totally don't understand why it doesn't work. What piece of this am I missing?

+4  A: 

you are missing the call to Initializecomponent() in your partial Class for ResourceDictionary

namespace YourNameSpace
{
    public partial class someClassName: ResourceDictionary
    {
        public someClassName()
        {
            InitializeComponent(); // you need this for the LoadComponent call on the Baml..
        }
    }
}
AppleDrink
Ah, you're right. I didn't realize that was the important glue to hold all of the pieces together. I thought it was a little more magical. Thanks for that, AppleDrink. I thought nobody was going to come up with an answer for that one. You're my hero.
MojoFilter