Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>All the code looks normal, except for the style of <code>MenuItemIcon</code>. Quote about <code>TemplateBinding</code> from Adam Nathan book:</p> <blockquote> <p>TemplateBinding doesn’t work outside a template or outside its VisualTree property, so you can’t even use TemplateBinding inside a template’s trigger. Furthermore, TemplateBinding doesn’t work when applied to a Freezable (for mostly artificial reasons).</p> </blockquote> <p>And quote from <a href="http://msdn.microsoft.com/ru-ru/library/system.windows.media.visualbrush.aspx" rel="nofollow"><code>MSDN</code></a> about <code>VisualBrush</code>:</p> <blockquote> <p>Freezable Features: Because it inherits from the Freezable class, the VisualBrush class provides several special features: VisualBrush objects can be declared as resources and shared among multiple objects.</p> </blockquote> <p>Therefore instead of:</p> <pre><code>&lt;VisualBrush Visual="{TemplateBinding Source}" /&gt; </code></pre> <p>Use the construction <code>{RelativeSource TemplatedParent}</code> and a <code>Path</code> equal to the dependency property whose value you want to retrieve:</p> <pre><code>&lt;Style TargetType="{x:Type local:MenuItemIcon}"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type local:MenuItemIcon}"&gt; &lt;Rectangle Width="22" Height="22"&gt; &lt;Rectangle.Fill&gt; &lt;VisualBrush Visual="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Source}" /&gt; &lt;/Rectangle.Fill&gt; &lt;/Rectangle&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre>
 

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