WPF images inside ResourceDictionary are singleton?

WPF ... if I add an image to my ResourceDictionary and later use StaticResource to use it in several places ... does this image have only one instance? or is a new instance of this image created every time I use it?

+6
source share
2 answers

Instance level
In the same instance of the element that contains the ResourceDictionary, yes, it always takes the same instance as you, do not say x: Shared = "false" .
For controls and images, this will be necessary if you want them to use them more than once. For ImageSources, no. This is because an element can have only one parent element.

Global level
However, resources are loaded for each instance. This means that if you define a resource in the UserControl resource section, one instance of the resource will be loaded for each instance of your UserControl. Place your frequently used resources in the Application Resources section or in the Windows Resources section.

Click here for more information.

+5
source

If you want ONE copy of downloadable resources, use Christian Moser SharedResourceDictionary at http://www.wpftutorial.net/MergedDictionaryPerformance.html

0
source

Source: https://habr.com/ru/post/891220/


All Articles