Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does ResourceDictionary change result in DynamicResource reevaluation?

If Resources dictionary is not observable, how does DynamicResource reference work? Do the Add / Remove methods of the resource dictionary have internal code that kind of "polls" all DynamicResource references and refreshes them when they are removed or added?

like image 337
WPF-it Avatar asked Aug 08 '11 07:08

WPF-it


People also ask

What is ResourceDictionary?

A resource dictionary is a repository for XAML resources, such as styles, that your app uses. You define the resources in XAML and can then retrieve them in XAML using the {StaticResource} markup extension and {ThemeResource} markup extension s. You can also access resources with code, but that is less common.

How to add ResourceDictionary in XAML?

To add more than one dictionary, just add a <ResourceDictionary Source="Dictionary2. xaml"/> entry after the first entry.

What is static resource in XAML?

A StaticResource will be resolved and assigned to the property during the loading of the XAML which occurs before the application is actually run. It will only be assigned once and any changes to resource dictionary ignored.


1 Answers

Each ResourceDictionary contains three list of owners. One for FrameworkElement, one for Application and another one for FrameworkContentElement. When you access the Resources property the owner is being set. Also each ResourceDictionary propagates its owner to merged dictionaries. When dictionary is changing, it notifies owners about it. This notification actually searches dependency properties with local values containing resource expression. Then each expression is forced to reevaluate.

All of this code is internal.

like image 143
Marat Khasanov Avatar answered Nov 05 '22 12:11

Marat Khasanov