Question

I need to apply a style in code ike this:

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

that will be updated dynamically when the resource dictionary is changed (i.e. skin is replaced at runtime). In other words I need the equivalent to using a dynamic resource like this:

<TextBlock Style="{DynamicResource MyStyle}" />
Was it helpful?

Solution

Try using SetResourceReference.

textBlock.SetResourceReference(TextBlock.StyleProperty, "MyStyle")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top