WPF images inside ResourceDictionary are singleton? WPF images inside ResourceDictionary are singleton? wpf wpf

WPF images inside ResourceDictionary are singleton?


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

Global Level
However resources are loaded for every instance. This means if you define a Resource in the resources section of a UserControl, for every instance of your UserControl one instance of the resource will be loaded. Put often used resources into the App Resources section or into the Windows Resources section.

Here you will find more information.


If you want ONE copy of the resources to be loaded, use Christian Moser's SharedResourceDictionary at http://www.wpftutorial.net/MergedDictionaryPerformance.html