Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 10. Control Skinning and Themes > Using Resources in Default Styles

Using Resources in Default Styles

When you define the default ControlTemplates for your custom controls, you will most likely use additional resources inside your template. These resources could include brushes, images, or additional templates. You should be careful not to define resources at the element level (for example, the root visual of your template). This is important because doing so limits the usage to only within the template or style. Unless you have a very special case where the resource will be used only once, try to put the resources at a level where it could be shared amongst many controls.

The recommended approach is to define resources in a separate ResourceDictionary and then include them inside the Generic.xaml file using the ResourceDictionary. MergedDictionaries property. The use of the MergedDictionaries property is a good practice to refactor the usage of resources. If you have a set of brushes that are being used at multiple places, you could extract them and keep in a separate ResourceDictionary. Later in the XAML where you use the brush, you could include it using the MergedDictionaries property. Here is how you would use it in Generic.xaml:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint