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???
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With