Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Add a <code>ResourceDictionary</code> (xaml) file to your project (assuming it's a class library - WPF custom control library), merge it on top of the <code>Generic.xaml</code>, then you will be able to refer to it and your <code>StaticResource</code> will work.</p> <p>You can also include the resource in the Generic.xaml (or whatever xaml file it is) file itself.</p> <p>Here is how your current dictionary should look like:</p> <pre><code>&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:local="clr-namespace:WpfCustomControlLibrary1"&gt; &lt;sys:String x:Key="myString"&gt;sdfasdf&lt;/sys:String&gt; &lt;Style TargetType="{x:Type local:CustomControl1}"&gt; &lt;Setter Property="Text" Value="{StaticResource myString}"/&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type local:CustomControl1}"&gt; &lt;Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"&gt; &lt;TextBlock Text="{TemplateBinding Text}"/&gt; &lt;/Border&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/ResourceDictionary&gt; </code></pre> <p>I initialized a design time instance of the above control in VS2010 and it showed the text (<code>Text</code> is a string DP property I manually added to the <code>CustomControl1</code>), which means it reads the <code>myString</code> resource.</p> <p>You can find some more specific info <a href="https://stackoverflow.com/questions/709087/load-a-resourcedictionary-from-an-assembly" title="Load a ResourceDictionary from an assembly">here</a> and <a href="https://stackoverflow.com/questions/706700/load-wpf-styles-or-other-static-resources-from-an-external-file-or-assembly" title="Load WPF styles or other Static Resources from an external file or assembly">here</a>.</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