I recently needed to set a dependency property to a DynamicResource reference in code. It’s easy enough to do in XAML, but a quick Google search turned up nothing which explained how to do it in the code-behind. Hopefully this blog post will rectify that situation.
The magic method is FrameworkElement’s SetResourceReference. Here is a quick demo:
XAML
C#
Great Josh! it’s great thing!
Doesn’t work in VS2008 for me, but this worked (almost, not all resource keys worked?!):
(Brush)new BrushConverter().ConvertFromString(“SomeResourceKey”);
Great, but is there any sort of GetResourceReference by which I can find the resource name which is used to set say for example Background of control?
I need it to give ability to change font, color,… on the fly:
1) user clicks on control ( in customization mode)
2) It selected font and color and …