How to apply dynamic style in code at runtime?

I need to apply style in ike code:

TextBlock.Style = TryFindResource("MyStyle") as Style;

which will be dynamically updated when the resource dictionary changes (i.e. the skin is replaced at run time). In other words, I need the equivalent of using a dynamic resource like this:

<TextBlock Style="{DynamicResource MyStyle}" />
+5
source share
1 answer

Try using SetResourceReference .

textBlock.SetResourceReference(TextBlock.StyleProperty, "MyStyle")
+13
source

All Articles