Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To gain access to the <code>Resource</code> of the code must identify them in the file <code>App.xaml</code>:</p> <pre><code>&lt;Application.Resources&gt; &lt;SolidColorBrush x:Key="DynamicBG" /&gt; &lt;/Application.Resources&gt; </code></pre> <p><code>XAML example</code></p> <pre><code>&lt;Grid&gt; &lt;Label Name="MyLabel" Content="Hello" Background="{DynamicResource DynamicBG}" /&gt; &lt;Button Content="Change color" Width="100" Height="30" Click="Button_Click" /&gt; &lt;/Grid&gt; </code></pre> <p>The <code>Resource</code> can be changed in code line of the form:</p> <pre><code>Application.Current.Resources["MyResource"] = MyNewValue; </code></pre> <p>Example:</p> <p><code>Code behind</code></p> <pre><code>// using ContentRendered event private void Window_ContentRendered(object sender, EventArgs e) { SolidColorBrush MyBrush = Brushes.Aquamarine; // Set the value Application.Current.Resources["DynamicBG"] = MyBrush; } private void Button_Click(object sender, RoutedEventArgs e) { SolidColorBrush MyBrush = Brushes.CadetBlue; // Set the value Application.Current.Resources["DynamicBG"] = MyBrush; } </code></pre> <p>Principle, <code>DynamicResources</code> were designed, so they can be changed. Where to change - it is the task of the developer. In the case of <code>Color</code>, it is one of the most common methods. See the <a href="http://msdn.microsoft.com/en-us/library/ms748942.aspx" rel="noreferrer">MSDN</a>, for more information.</p> <p>P. S. I recommend using <code>App.xaml</code>, because there have been cases where a <code>StaticResource</code> has been used successfully, but not <code>DynamicResource</code> (resources are placed in the <code>Window.Resources</code>). But after moving the resource in <code>App.xaml</code>, everything started to work. </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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