Difference between Staticresource and Themeresource UWP uses?

Asked

Viewed 59 times

-1

To declare a Textblock with Headertextblockstyle style you can use these two forms where the result is the same:

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

Is there any difference between these two? And what situation is best suited to use Staticresource and Themeresource?

  • 1

    Related: https://answall.com/q/173387/101

1 answer

1


According to the documentation of Microsoft:

(Text taken from documentation)

To Themeresource is a technique for obtaining values referring to a XAML attribute defined elsewhere in a XAML resource dictionary. This marking extension has the same basic purpose as the marking extension Staticresource.

The difference in behaviour in relation to the marking extension {Staticresource} is that a reference Themeresource can dynamically use different dictionaries as the main search location, depending on the theme currently used by the system.

When and how to use {Themeresource} instead of {Staticresource}?

The rules by which Themeresource is solved for an item in a resource dictionary are usually the same as in Staticresource. A Themeresource search can be extended to the Resourcedictionary files that are referenced in a collection of Themedictionaries, 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:
https://docs.microsoft.com/pt-br/windows/uwp/xaml-platform/staticresource-markup-extension
https://docs.microsoft.com/pt-br/windows/uwp/xaml-platform/themeresource-markup-extension

Browser other questions tagged

You are not signed in. Login or sign up in order to post.