开发者

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 hav开发者_如何学Ce only one instance? or does a new instance of that image is created each time i use it?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜