Note that there are some explanatory texts on larger screens.

plurals
  1. POLinked resource dictionary and StaticResource reference at root level
    text
    copied!<p>I'm aware of <a href="https://stackoverflow.com/questions/12534611/setting-a-style-to-a-static-resource-for-a-root-control-element">this</a>, which doesn't apply to my case, and <a href="https://stackoverflow.com/questions/2371100/use-staticresource-in-xaml-root-element">this</a>, which I'm not sure whether it can be adapted.</p> <p>I'm working on a WPF control library, and I don't have an App.xaml file. I use a file called <strong>Styles.xml</strong> to store common brushes and other resources. In the XAML file of my user control I import the resources and then I try to use brush <strong>sBrush</strong> as a background.</p> <p>This works except that at the root level:</p> <pre><code>&lt;UserControl x:Class="CMControls.TitledWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" Background="{StaticResource ResourceKey=sBrush}"&gt; &lt;!--EXCEPTION!--&gt; &lt;UserControl.Resources&gt; &lt;ResourceDictionary&gt; &lt;ResourceDictionary.MergedDictionaries&gt; &lt;ResourceDictionary Source="pack://application:,,,/CMControls;component/Styles.xaml"/&gt; &lt;/ResourceDictionary.MergedDictionaries&gt; &lt;/ResourceDictionary&gt; &lt;/UserControl.Resources&gt; &lt;Canvas Background="{StaticResource ResourceKey=sBrush}" ... &lt;!--Ok.--&gt; ... </code></pre> <p>I presume this happens because when the root element is instantiated its children are not, including <strong>UserControl.Resources</strong>. Is there any workaround? <strong>Note that in the designer everything works fine, no matter where I make the reference</strong>.</p>
 

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