Note that there are some explanatory texts on larger screens.

plurals
  1. POStatic resource shared in merged dictionaries
    primarykey
    data
    text
    <p>I'm currently working on having dictionaries of styles and templates that I can dynamically apply to my application. Before this "new wanted" dynamical behavior, I had several resource dictionaries, one for each styled control, that I merged in the App.xaml: </p> <pre class="lang-xml prettyprint-override"><code>&lt;Application.Resources&gt; &lt;ResourceDictionary&gt; &lt;ResourceDictionary.MergedDictionaries&gt; &lt;ResourceDictionary Source="ColorsDictionary.xaml"/&gt; &lt;ResourceDictionary Source="ControlsTemplatesDictionary.xaml"/&gt; &lt;/ResourceDictionary.MergedDictionaries&gt; &lt;/ResourceDictionary&gt; &lt;/Application.Resources&gt; </code></pre> <p>Now, I'd like my application to be styled, so I decided to merge all my previous resources into a new one called "MyFirstTemplates" and to add only this dictionary to the App.xaml.</p> <p>New dictionary "MyFirstTemplates.xaml":</p> <pre class="lang-xml prettyprint-override"><code>&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;" &lt;ResourceDictionary.MergedDictionaries&gt; &lt;ResourceDictionary Source="ColorsDictionary.xaml"/&gt; &lt;ResourceDictionary Source="ControlsTemplatesDictionary.xaml"/&gt; &lt;/ResourceDictionary.MergedDictionaries&gt; &lt;/ResourceDictionary&gt; </code></pre> <p>New App.xaml:</p> <pre class="lang-xml prettyprint-override"><code>&lt;Application.Resources&gt; &lt;ResourceDictionary&gt; &lt;ResourceDictionary.MergedDictionaries&gt; &lt;ResourceDictionary Source="MyFirstTemplates.xaml"/&gt; &lt;/ResourceDictionary.MergedDictionaries&gt; &lt;Style TargetType="{x:Type Window}"/&gt; &lt;/ResourceDictionary&gt; &lt;/Application.Resources&gt; </code></pre> <p>Note: The default style for the <em>Window</em> is to correct a bug of WPF 4, see <a href="https://stackoverflow.com/questions/3419543/adding-a-merged-dictionary-to-a-merged-dictionary/4113594#4113594">Adding a Merged Dictionary to a Merged Dictionary</a></p> <p>Now that I have made this change, I cannot use a color resource from "ColorsDictionary.xaml" as a <em>StaticResource</em> in "ControlsTemplateDictionary.xaml" anymore. If I change back to merging these files in the app.xaml, everything works. To make it work, I have to change these <em>StaticResource</em> for <em>DynamicResource</em>. Do you have any idea why this doesn't work anymore?</p> <p>Thank you :-)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload