Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can create 3 resource dictionaries and merge them at runtime. In my example code I used two resource dictionaries.</p> <p>Example:</p> <p><em>Dictionary1.xaml</em>:</p> <pre><code>&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt; &lt;Style x:Key="btnStyle" TargetType="Button"&gt; &lt;Setter Property="Margin" Value="0,10,0,0" /&gt; &lt;/Style&gt; &lt;/ResourceDictionary&gt; </code></pre> <p><em>Dictionary2.xaml</em>:</p> <pre><code>&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt; &lt;Style x:Key="btnStyle" TargetType="Button"&gt; &lt;Setter Property="Margin" Value="50,50,0,0" /&gt; &lt;/Style&gt; &lt;/ResourceDictionary&gt; </code></pre> <p>In the start of application you can set default style in <code>App.xaml</code> file:</p> <pre><code>&lt;Application x:Class="Example.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"&gt; &lt;Application.Resources&gt; &lt;ResourceDictionary&gt; &lt;ResourceDictionary.MergedDictionaries&gt; &lt;ResourceDictionary Source="/Dictionary1.xaml" /&gt; &lt;/ResourceDictionary.MergedDictionaries&gt; &lt;/ResourceDictionary&gt; &lt;/Application.Resources&gt; &lt;/Application&gt; </code></pre> <p>If you want to change style, you can merge resource dictionaries:</p> <pre><code>ResourceDictionary dict = new ResourceDictionary(); dict.Source = new Uri("\\Dictionary2.xaml", UriKind.Relative); this.Resources.MergedDictionaries.Add(dict); </code></pre> <p>And now binding looks like this:</p> <pre><code>&lt;Button Style="{DynamicResource btnStyle}" Content="Click me!" /&gt; </code></pre> <p>Now if you invoke code to merge resource dictionaries, button style will be automatically changed.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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