Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

Silverlight 3 - Merged Dictionary Rules

, 21 May 2010
Rate this:
Please Sign up or sign in to vote.
Follow these guidelines for trouble-free dictionary merging in Silverlight
Silverlight 3 allows you to use merged dictionaries, but in order to be successful, you have to know and adhere to the unspoken (and barely documented) rules. I fought with this for half a day before stumbling on the solution to my problem. So that you don't suffer the same fate, I present you with said solution. I assume that you're working on a Silverlight (or WPF) application and are familiar with all of the nomenclature I'm about to use, and that you're just here to laugh and point (and that's okay). Smile | :)
 
Here was my situation. I've been working on a SL3 (navigation) app for about a month. When you create a new app of this type, Visual Studio creates a folder in the project called Assets, and in that folder, it places a resource dictionary called Styles.XAML, containing all of the resources necessary to create the default appearance of the templated application. Then in App.XAML, they merge the Styles.XAML dictionary into the application.
 
I've been working on my (navigation) app for about a month, steadily adding styles, brushes, templates, and other resources to the original dictionary. This morning, I decided to break the (now huge) dictionary into smaller more targetted files. Let's call one Colors, and two others named Cat and Dog. Both Cat and Dog use reosurces in Colors, and the app uses all three.
 
Here are the rules:
 
0) Because both Cat and Dog use resources from Colors, BOTH Cat and Dog have to have a MergedDictionaries section, like so:
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/AssemblyName;component/Assets/Colors.xaml"/>
    </ResourceDictionary.MergedDictionaries>
Notice the need for "/AssemblyName;component/". You MUST include this, even if the resource dictionary is part of the same assembly.
 
1) In App.XAML, you need to add all three dictionaries to the existing MergedDictionaries section:
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Assets/Dog.xaml"/>
        <ResourceDictionary Source="Assets/Cat.xaml"/>
        <ResourceDictionary Source="Assets/Colors.xaml"/>
    </ResourceDictionary.MergedDictionaries>
Notice the ABSENCE of "/AssemblyName;component/". If you include that phrase in App.XAML, your dictionaries will not merge (at least, they didn't for me).
 
Silverlight continues to shine as the fragile house of cards that we all know it to be. Good luck.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

John Simmons / outlaw programmer
Software Developer (Senior)
United States United States
I've been paid as a programmer since 1982 with experience in Pascal, and C++ (both self-taught), and began writing Windows programs in 1991 using Visual C++ and MFC. In the 2nd half of 2007, I started writing C# Windows Forms and ASP.Net applications, and have since done WPF, Silverlight, WCF, web services, and Windows services.
 
My weakest point is that my moments of clarity are too brief to hold a meaningful conversation that requires more than 30 seconds to complete. Thankfully, grunts of agreement are all that is required to conduct most discussions without committing to any particular belief system.

Comments and Discussions

 
GeneralThis article is great. Pinmemberfelipe20514-Apr-13 1:26 
GeneralI wish I could give a 6 for this...5 for the tip and +1 for ... PinmemberTheyCallMeMrJames18-May-10 5:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 21 May 2010
Article Copyright 2010 by John Simmons / outlaw programmer
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid