SilverlightShow: Merged Resource Dictionaries in Silverlight Comments http://www.silverlightshow.net/ Silverlight articles, Silverlight tutorials, Silverlight videos, Silverlight samples SilverlightShow.net http://www.rssboard.org/rss-specification Argotic Syndication Framework 2008.0.2.0, http://www.codeplex.com/Argotic en-US estoychev@completit.com (Emil Stoychev) RE: Merged Resource Dictionaries in Silverlight <em><span style="font-size: 11pt; line-height: 115%; font-family: calibri, sans-serif;">The article has been updated to the latest version of Silverlight and Visual Studio.</span></em> http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx#comment5622 lnikolov http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx Tue, 01 Mar 2011 11:03:09 GMT RE: Merged Resource Dictionaries in Silverlight 3 This works for me in Silverlight 3, but when I try it in Silverlight 4 it crashes - has anyone else tried it? http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx#comment4521 Rob263 http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx Mon, 20 Sep 2010 19:36:40 GMT http://welcome-re.ru/ <p>Your article is really very interesting. This is the information, I’ve been looking for… Thanks</p> <p><a href="http://welcome-re.ru/karelia.aspx" title="Недвижимость в Карелии">Недвижимость в Карелии</a></p> http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx#comment3729 JerryMirro http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx Sat, 05 Jun 2010 10:05:27 GMT RE: Merged Resource Dictionaries in Silverlight 3 <p>Emil,</p> <p>Thanks for the post. Consider the following scenario: You have a custom control library (called: "SomeOtherLibrary") with one customized UserControl in it, called "CustomControl." CustomControl merges a ResourceDictionary from an assembly called "External_ResourceLibraries," like so:</p> <p> <div style="border: 1px solid #7f9db9; overflow-y: auto;" class="reCodeBlock"> <div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #000000;"><</code><code style="color: #006699; font-weight: bold;">UserControl.Resources</code><code style="color: #000000;">></code></span></div> <div style="background-color: #f8f8f8;"><span><code>        </code><span style="margin-left: 24px ! important;"><code style="color: #000000;"><</code><code style="color: #006699; font-weight: bold;">ResourceDictionary</code><code style="color: #000000;">></code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px ! important;"><code style="color: #000000;"><</code><code style="color: #006699; font-weight: bold;">ResourceDictionary.MergedDictionaries</code><code style="color: #000000;">></code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                </code><span style="margin-left: 48px ! important;"><code style="color: #000000;"><</code><code style="color: #006699; font-weight: bold;">ResourceDictionary</code> <code style="color: #808080;">Source</code><code style="color: #000000;">=</code><code style="color: blue;">"/External_ResourceLibraries;component/BasicStylesDictionary.xaml"</code> <code style="color: #000000;">/></code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px ! important;"><code style="color: #000000;"></</code><code style="color: #006699; font-weight: bold;">ResourceDictionary.MergedDictionaries</code><code style="color: #000000;">></code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>        </code><span style="margin-left: 24px ! important;"><code style="color: #000000;"></</code><code style="color: #006699; font-weight: bold;">ResourceDictionary</code><code style="color: #000000;">></code></span></span></div> <div style="background-color: #ffffff;"><span><code>    </code><span style="margin-left: 12px ! important;"><code style="color: #000000;"></</code><code style="color: #006699; font-weight: bold;">UserControl.Resources</code><code style="color: #000000;">></code></span></span></div> </div> </p> <p>Let's say that you look at that customized UserControl in Blend and experience no problems. Now let's say you try to use that customized UserControl in your web application like this:<br /> <br /> <div style="border: 1px solid #7f9db9; overflow-y: auto;" class="reCodeBlock"> <div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #000000;"><</code><code style="color: #006699; font-weight: bold;">SomeOtherLibrary:CustomControl</code> <code style="color: #000000;">/></code></span></div> </div> </p> <p>Should the UserControl that creates an instance of "CustomControl" have to have a reference to the External_ResourceLibraries assembly in order to run? I have an application that works in this way, and need to know if this is the appropriate way of using MergedDictionaries in custom UserControl libraries. This process seems redundant, inefficient, and illogical. Can you help me understand why this custom UserControl can't be used in another UserControl's assembly without explicit references to the External_ResourceLibraries that it attempts to merge together?</p> <p>Thanks,</p> <p>- Aaron</p> <p></p> http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx#comment3113 Aaron http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx Mon, 22 Feb 2010 21:59:14 GMT RE: Merged Resource Dictionaries in Silverlight 3 <p>I've tried to use it on a generic.xaml but it doesn't work.</p> <p>My struct is like this:</p> <ul> <li>SilverlightClassLibrary1 <ul> <li>Themes <ul> <li>generic.xaml</li> </ul> </li> <li>CT <ul> <li>MyTabControl.xaml</li> </ul> </li> <li>MyTabControl.cs</li> </ul> </li> </ul> <p>MyTabControl is my custom control that inherit ItemsControl. MyTabControl.xaml contains all ControlTemplate(s) and properties definition.</p> <p>I tried to insert in generic.xaml:</p> <div style="border: #7f9db9 1px solid; font-family: courier new; background-color: white;"> <table style="border-top-width: 0px; border-left-width: 0px; margin: 2px 0px; width: 99%; border-bottom: #eee 0px solid; border-collapse: collapse; background-color: #fff; border-right-width: 0px;" cellspacing="0" cellpadding="0"> <colgroup><col style="padding-left: 10px; font-size: 11px; border-bottom: #f7f7f7 1px solid; font-family: courier new; white-space: nowrap;" /></colgroup> <tbody> <tr> <td><span style="font-size: 11px;"></span><span style="color: blue;"><</span><span style="font-size: 11px;">ResourceDictionary.MergedDictionaries</span><span style="color: blue;">></span><span style="font-size: 11px;"> </span></td> </tr> <tr> <td style="background-color: #f7f7f7;">    <span style="color: blue;"><</span><span style="font-size: 11px;">ResourceDictionary </span><span style="color: red;">Source</span><span style="font-size: 11px;">=</span><span style="color: blue;">"/local;/CT/MyTabControl.xaml"</span><span style="font-size: 11px;"> </span><span style="color: blue;">/></span><span style="font-size: 11px;"> </span></td> </tr> <tr> <td><span style="color: blue;"></</span><span style="font-size: 11px;">ResourceDictionary.MergedDictionaries</span><span style="color: blue;">></span><span style="font-size: 11px;"> </span></td> </tr> </tbody> </table> </div> <p>But it doesn't work, why? Thanks.<span style="font-size: 10px; color: #0000ff;"> <p> </p> </span></p> http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx#comment2543 Merlinox http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx Tue, 13 Oct 2009 11:50:00 GMT RE: Merged Resource Dictionaries in Silverlight 3 Thank you Assaf, it is useful to know that! http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx#comment2282 emil http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx Tue, 25 Aug 2009 09:30:50 GMT RE: Merged Resource Dictionaries in Silverlight 3 I've came across another issue -<div><br /></div><div>When the external assembly name contains dots (for example <em>AssemblyNamePart1.Part2</em>), an error is thrown.</div><div>After removing the dots (e.g. <em>AssemblyNamePart1_Part2</em>), everything worked fine.</div><div><br /></div><div>Assaf</div> http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx#comment2280 Assaf S. http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx Mon, 24 Aug 2009 20:54:41 GMT RE: Merged Resource Dictionaries in Silverlight 3 Hi sidhu,<div><br /></div><div>the problem is that the code was compiled with Silverlight 3 Beta. For Silverlight 3 RTW you need to put a slash '/' at the beginning of the source path. Like this:</div><div><span style="color: rgb(83, 83, 83); font-family: arial; font-size: 14px; line-height: 20px; "> <ResourceDictionary Source="<strong>/</strong>ExternalResources;component/DataResources.xaml" /><br /><ResourceDictionary Source="<strong>/</strong>MergedResourceDictionaries;component/TextResources.xaml" /></span><br /></div><div><span style="font-family: arial; color: rgb(83, 83, 83); font-size: 14px; line-height: 20px; "><br /></span></div><div><span style="font-family: arial; color: rgb(83, 83, 83); font-size: 14px; line-height: 20px; ">Hope that helps!</span></div> http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx#comment2231 emil http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx Wed, 12 Aug 2009 10:13:54 GMT RE: Merged Resource Dictionaries in Silverlight 3 I downloaded your source code and tried to run it. I got runtime errors in InitializeComponent(xmlParserException with message  Attribute ExternalResources;component/DataResources.xaml value is out of range. [Line: 8 Position: 44]) for both <p> <ResourceDictionary Source="ExternalResources;component/DataResources.xaml" /><br /> <ResourceDictionary Source="MergedResourceDictionaries;component/TextResources.xaml" />  </p> <p>It worked fine if i comment both these lines. Is there any settings I need to change? or copy any resource files?</p> <br /> http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx#comment2229 sidhu http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx Wed, 12 Aug 2009 01:42:45 GMT RE: Merged Resource Dictionaries in Silverlight 3 I downloaded your source code and tried to run it. I got runtime errors in InitializeComponent(xmlParserException with message  Attribute ExternalResources;component/DataResources.xaml value is out of range. [Line: 8 Position: 44]) for both <p> <ResourceDictionary Source="ExternalResources;component/DataResources.xaml" /><br /> <ResourceDictionary Source="MergedResourceDictionaries;component/TextResources.xaml" />  </p> <p>It worked fine if i comment both these lines. Is there any settings I need to change? or copy any resource files?</p> <br /> http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx#comment2228 sidhu http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx Wed, 12 Aug 2009 01:41:52 GMT RE: Merged Resource Dictionaries in Silverlight 3 Hi Emil,<br /><br />I am trying to do the following:<br />I have a resource project ResDict with 2 files: styles.xaml and assets.xaml.<br />styles.xaml needs the info in  assets.xaml (brushes).<br />styles.xaml is used in another SL project MainPrj.<br /><br />following your indications, I was able to use the styles in styles.xaml in the MainPrj, when styles.xaml doesn't use the brushes in assets.xaml.<br /><br />how can I use the definition in assets.xaml within styles.xaml in my MainPrj?<br /><br />ADDITIONAL INFO:<br /><br />Build action for style.xaml and assets.xaml is Resource.<br /><br />Code in style.xaml:<br /><span style="font-size: 13px; color: rgb(163, 21, 21); "><p> <span style="color: rgb(0, 0, 0); font-size: 16px; "><span style="font-size: 13px; color: rgb(0, 0, 255); "><</span><span style="font-size: 13px; color: rgb(163, 21, 21); ">ResourceDictionary.MergedDictionaries</span><span style="font-size: 13px; color: rgb(0, 0, 255); ">><span style="font-size: 13px; color: rgb(0, 0, 255); "></span></span></span></p><p><span style="color: rgb(0, 0, 0); font-size: 16px; "><span style="font-size: 13px; color: rgb(0, 0, 255); ">    <</span><span style="font-size: 13px; color: rgb(163, 21, 21); ">ResourceDictionary</span><span style="font-size: 13px; color: rgb(255, 0, 0); "> Source</span><span style="font-size: 13px; color: rgb(0, 0, 255); ">="ResDict;component/assets.xaml"/><span style="color: rgb(163, 21, 21); "> </span></span></span></p></span><p><span style="font-size: 13px; color: rgb(0, 0, 255); "></</span><span style="font-size: 13px; color: rgb(163, 21, 21); ">ResourceDictionary.MergedDictionaries</span><span style="font-size: 13px; color: rgb(0, 0, 255); ">><span style="color: rgb(0, 0, 0); font-size: 16px; "> </span></span></p><p></p>Code in App.xaml in PrjMain<br /><span style="font-size: 13px; color: rgb(163, 21, 21); "><p> <span style="color: rgb(0, 0, 0); font-size: 16px; "><span style="font-size: 13px; color: rgb(0, 0, 255); "><</span><span style="font-size: 13px; color: rgb(163, 21, 21); ">Application.Resources</span><span style="font-size: 13px; color: rgb(0, 0, 255); ">><span style="color: rgb(163, 21, 21); "> </span></span></span></p></span><p><span style="font-size: 13px; color: rgb(0, 0, 255); ">    <</span><span style="font-size: 13px; color: rgb(163, 21, 21); ">ResourceDictionary</span><span style="font-size: 13px; color: rgb(255, 0, 0); "> Source</span><span style="font-size: 13px; color: rgb(0, 0, 255); ">="ResDict;component/styles.xaml" /><span style="color: rgb(163, 21, 21); "> </span></span></p><p><span style="font-size: 13px; color: rgb(0, 0, 255); "></</span><span style="font-size: 13px; color: rgb(163, 21, 21); ">Application.Resources</span><span style="font-size: 13px; color: rgb(0, 0, 255); ">><span style="color: rgb(0, 0, 0); font-size: 16px; "> </span></span></p><p></p>Thank you very much in advance for your help!<br /> http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx#comment1373 smalle http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx Tue, 31 Mar 2009 09:19:26 GMT RE: Merged Resource Dictionaries in Silverlight 3 <div style="padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; background-image: none; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-align: left; word-wrap: break-word; ">@Pavel, did you look at the source code? You can see that I included DataResources.xaml as a Resource in external assembly (ExternalResources) and then use it without any problems in MergedResourceDictionaries assembly. Take a look at it and let me know whether there is something not clear.<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br /></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">@Ryan, there is no problem to do that. Here is what you need to do:<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; overflow-x: auto; overflow-y: auto; background-color: white; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-color: rgb(127, 157, 185); border-right-color: rgb(127, 157, 185); border-bottom-color: rgb(127, 157, 185); border-left-color: rgb(127, 157, 185); line-height: 11px; font-family: 'courier new'; font-size: 11px; "><table cellpadding="0" cellspacing="0" style="border-right-color: rgb(153, 153, 153); border-right-width: 0px; border-right-style: dashed; border-bottom-color: rgb(238, 238, 238); border-bottom-width: 0px; border-bottom-style: solid; width: 767px; margin-top: 2px; margin-right: 0px; margin-bottom: 2px; margin-left: 0px; border-collapse: collapse; background-color: rgb(255, 255, 255); border-top-width: 0px; border-left-width: 0px; "> <col style="font-family: 'courier new'; font-size: 11px; background-color: rgb(238, 238, 238); padding-right: 5px; padding-left: 10px; width: 5px; border-right-width: 1px; border-right-style: solid; border-right-color: gray; color: gray; text-align: right; vertical-align: top; " /><col style="font-family: 'courier new'; font-size: 11px; padding-left: 10px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(247, 247, 247); white-space: nowrap; " /> <tbody> <tr> <td style="padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-color: rgb(153, 153, 153); border-top-width: 1px; border-top-style: dashed; border-left-color: rgb(153, 153, 153); border-left-width: 1px; border-left-style: dashed; "><nobr>1</nobr></td> <td style="padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-color: rgb(153, 153, 153); border-top-width: 1px; border-top-style: dashed; border-left-color: rgb(153, 153, 153); border-left-width: 1px; border-left-style: dashed; "><span style="font-size: 11px; "></span><span style="color: blue; "><</span><span style="font-size: 11px; ">ResourceDictionary </span><span style="color: red; ">Source</span><span style="font-size: 11px; ">=</span><span style="color: blue; ">"MergedResourceDictionaries;component/SubFolder/SubBrushResources.xaml"</span><span style="font-size: 11px; "> </span><span style="color: blue; ">/></span><span style="font-size: 11px; "> </span></td> </tr> <tr> <td style="padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-color: rgb(153, 153, 153); border-top-width: 1px; border-top-style: dashed; border-left-color: rgb(153, 153, 153); border-left-width: 1px; border-left-style: dashed; "><nobr>2</nobr></td> <td style="padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; border-top-color: rgb(153, 153, 153); border-top-width: 1px; border-top-style: dashed; border-left-color: rgb(153, 153, 153); border-left-width: 1px; border-left-style: dashed; background-color: rgb(247, 247, 247); "><span style="color: blue; "><</span><span style="font-size: 11px; ">ResourceDictionary </span><span style="color: red; ">Source</span><span style="font-size: 11px; ">=</span><span style="color: blue; ">"/SubFolder/SubBrushResources.xaml"</span><span style="font-size: 11px; "> </span><span style="color: blue; ">/></span><span style="font-size: 11px; "> </span></td> </tr> </tbody></table></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br /></div>If you include your resources as a Resource (build action) you should you use the snippet on the first line where: MergedResourceDictionaries is the assembly name<br />SubFolder is the name of the sub folder where you put your resources<br />SubBrushResources.xaml is the name of your resource dictionary file<br /></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br /></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">If you include your resources as a Content (build action) you should use the snippet on the second line where:</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">SubFolder is the name of the sub folder where you put your resources<br />SubBrushResources.xaml is the name of your resource dictionary file<br /></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br /></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">Does this make sense to you?</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br /></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">Hope that helps!</div></div> http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx#comment1263 emil http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx Tue, 24 Mar 2009 04:27:40 GMT RE: Merged Resource Dictionaries in Silverlight 3 hi guys what about resources in difference file dictionary?<br /> for example move main.xaml to a subfold whatever,<br /> that just throw a exception.and there is no documentation there for a reference,please tell me how to resolve http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx#comment1260 Ryan lin http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx Tue, 24 Mar 2009 01:33:08 GMT RE: Merged Resource Dictionaries in Silverlight 3 Including resources as Resource does not work when I try to use it in an external assembly. May work in WPF~21~3f I kept the ResourceDictionary as a Page and everything worked fine.~3cbr /~3e http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx#comment1259 Pavel http://www.silverlightshow.net/items/Merged-Resource-Dictionaries-in-Silverlight-3.aspx Tue, 24 Mar 2009 00:14:37 GMT