Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can add an additional data trigger to examine the ContextMenu's IsOpen property through binding.</p> <pre><code>&lt;DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=ContextMenu.IsOpen}" Value="True"&gt; &lt;Setter TargetName="NavLinkBorder" Property="Background" Value="#CCCCCC" /&gt; &lt;Setter Property="Cursor" Value="Hand" /&gt; &lt;/DataTrigger&gt; </code></pre> <p>You can also get rid of the MouseOver="false" trigger and just set Background="#EAEAEA" on NavLinkBorder as the default value which will take over when no triggers are active.</p> <p>Alternately, you can switch the border color setting to use template binding, which would help your code method to work. This is a good practice to use anyway as it makes your templates more flexible since different Background values can be set on individual Label instances. Here's the Style with some TemplateBindings and the context menu trigger added.</p> <pre><code>&lt;Style TargetType="{x:Type Label}" x:Key="NavLink"&gt; &lt;Setter Property="Background" Value="#EAEAEA" /&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate x:Name="NavLinkControlTemplate" TargetType="{x:Type Label}"&gt; &lt;Border x:Name="NavLinkBorder" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"&gt; &lt;ContentPresenter x:Name="NavLinkContent" Margin="4,4,4,4" /&gt; &lt;/Border&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="IsMouseOver" Value="True"&gt; &lt;Setter TargetName="NavLinkBorder" Property="Background" Value="#CCCCCC" /&gt; &lt;Setter Property="Cursor" Value="Hand" /&gt; &lt;/Trigger&gt; &lt;DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=ContextMenu.IsOpen}" Value="True"&gt; &lt;Setter TargetName="NavLinkBorder" Property="Background" Value="#CCCCCC" /&gt; &lt;Setter Property="Cursor" Value="Hand" /&gt; &lt;/DataTrigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre>
    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. 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