Difference between StaticResource and ThemeResource UWP uses?

0

To declare a TextBlock with style HeaderTextBlockStyle you can use these two ways where the result is the same:

<TextBlock Text="Olá, Mundo!" Style="{StaticResource HeaderTextBlockStyle}" />
<TextBlock Text="Olá, Mundo!" Style="{ThemeResource HeaderTextBlockStyle}" />

Is there a difference between these two? And what situation is most appropriate for using StaticResource and ThemeResource?

    
asked by anonymous 27.04.2017 / 20:30

1 answer

0

According to the Microsoft documentation :

(Text removed from documentation)

The ThemeResource is a technique for retrieving values for a XAML attribute defined elsewhere in a XAML resource dictionary. This markup extension has the same basic purpose as the StaticResource markup extension.

The difference in behavior regarding the {StaticResource} tag extension is that a ThemeResource reference can dynamically use different dictionaries as the primary search location, depending on the theme currently being used by the system.

When and how to use {ThemeResource} instead of {StaticResource}?

The rules by which ThemeResource is resolved to an item in a resource dictionary are usually the same as StaticResource. A ThemeResource search can be extended to ResourceDictionary files that are referenced in a ThemeDictionaries collection, but a StaticResource can also do this. A diferença é que um ThemeResource pode ser reavaliado no tempo de execução e um StaticResource não.

References:
link
link

    
29.04.2017 / 22:08