views:

167

answers:

2

Here is the scenario:

1) Open Visual Studio 2008, create new project...

2) Select WPF Custom Control Library as the project type

3) Open the Generic.xaml resource dictionary located in the Themes folder

4) Add a simple brush such as:

< SolidColorBrush x:Key="BackgroundBrush" Color="Yellow" / >

5) Change the Background property of the nested Borer Control from

Background="{TemplateBinding Background}"

to

Background="{DynamicResource BackgroundBrush}"

Now when you compile and use this control in any project, the background will NOT be yellow. BUT, if you change the background property to be a StaticResource as such

Background="{StaticResource BackgroundBrush}"

...it will work. Why is this? Why does StaticResource work but not DynamicResource???

A: 

If you are hard coding the brush in Xaml file, that sounds pretty static to me.

The MSDN entry for DynamicResource say this is for when you want the use resolve the name of the resource at run time (ie the name is stored in a another resource), where you know the name at compile time.

Sounds very much like a pointer verse a pointer-to-a-pointer from C.

Simeon Pilgrim
A: 

I don't understand your answer. There is no hard-coding, this is the way Resources are defined. Nothing about pointers here.

Max