I have a user control and it uses resource dictionaries. In that user control, there is another user control which uses same resource dictionaries.what I want to know is whether wpf actually loads it twice and if yes, is there any perfomance impact. Is there any better way to do this.
Thanks in advance.
Interesting question. I was intrigged enough to investigate. It appears that WPF loads a new ResourceDirectionary (and all resources defined and the dictionary which are used) for each appearance of element.
Take a look at the following code:
ViewModel:
Resource (Dictionary1.xaml):
View:
Put a breakpoint at the Person() constructor and notice the object is instantiated twice. Or, make Person implementing INotifyPropertyChange, and add the following code for Button_Click:
If you want to have a single instance of each resource, have the reousrces in the element of app.xaml file.