Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF images inside ResourceDictionary are singleton?

WPF... if i add an image to my ResourceDictionary and later use StaticResource to use it at multiple places... does that image have only one instance? or does a new instance of that image is created each time i use it?

like image 335
shemesh Avatar asked Jun 23 '11 14:06

shemesh


1 Answers

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.

like image 193
HCL Avatar answered Oct 25 '22 08:10

HCL