Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF merged resource dictionaries in every user control - bad idea?

Tags:

resharper

wpf

I keep my app's resources in a separate DLL and reference them in my main EXE using something like this in App.xaml:-

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="pack://application:,,,/MyThemesAssembly;component/Themes/Generic.xaml"/>
</ResourceDictionary.MergedDictionaries>

When I edit a window that's in the main EXE project, the VS2010 designer doesn't recognise any resources from the other assembly, so I don't see any styling applied (not really an issue as I always work in the XAML view). However Resharper doesn't recognise these external resource names either, resulting in lots of squiggles under resource names when I'm editing XAML.

I've found that I can fix both the VS designer and Resharper by including the above XAML in each window and user control, but is this going to have an adverse effect on memory and/or performance? Will each window get a separate copy of the resources?

like image 654
Andrew Stephens Avatar asked Nov 01 '12 11:11

Andrew Stephens


1 Answers

We had a problem in our application with the use of ResourceDictionaries referenced in each UserControl / View. I advise against that. We managed to reduce our application's memory footprint by like 300 mb by the use of SharedResourceDictionaries. I looks like you will end up with the ResourceDictionary being instantiated once for every single UserControl in your application. Don't do that just to fix VS designer.

like image 118
Federico Berasategui Avatar answered Nov 03 '22 19:11

Federico Berasategui