Note: The examples are based on version 1.0 Milestone 1.
The Test Suite reference implementation defines a few control styles to meet the Microsoft Windows User Experience Interaction Guidelines. I have defined some of the “Recommended sizing
and spacing” rules found in the page “Layout”. I would like to apply these default settings to all WPF views in all modules.
My requirements for shared resources are:
- UI Designers must be able to read them at design time (e.g. Cider, Expression Blend).
- The same resources must not be loaded multiple times. Just once for all modules.
- Code-behind in the Xaml views should be avoided to retrieve the shared resources.
The approach I’m using in version 1.0 Milestone 1 is simple. I have included the shared resource file with the property MergedDictionaries into every single WPF view.
Example: Message.Demo / Views / DemoView.xaml
The main disadvantage of this approach is that the resources are loaded for every single view. This might require extensive memory usage if you put a lot of resources in the shared resource dictionary or you have many views. The MSDN article “Control
Authoring Overview” shows an alternative approach in the chapter “Defining and Using Shared Resources for Your Control”. They introduce a static class called SharedDictionaryManager which is responsible that a specific resource file gets loaded just once.
If the resource file is already loaded then it returns the cached ResourceDictionary object. However, this approach needs you to write code-behind to merge the shared dictionary with the resource dictionary of your WPF view.
Do you have a better idea how to define and use shared resources?