Note that there are some explanatory texts on larger screens.

plurals
  1. POHigh contrast trigger on a WPF window
    text
    copied!<p>I'm trying to apply a trigger to a base WPF window I made. I can successfully apply styles to it but the trigger doesn't seem to work. </p> <p>Essentially what I'm doing is at runtime I'm dumping the current resource dictionaries in the application and loading in another set of resource dictionaries to account for high contrast. It seems to be working, but I'm trying to work out a solution of images that need to be handled in high contrast mode. In this particular case the Window's background is set to an ImageBrush. I'm trying to use a trigger to set the background to a system color when in high contrast mode. </p> <p>I tried <a href="http://social.msdn.microsoft.com/Forums/en/wpf/thread/ba9a379b-4f02-408c-954b-6057e6d0a1b5" rel="nofollow">this solution</a> but neither seem to work:</p> <pre class="lang-xml prettyprint-override"><code>&lt;Style TargetType="{x:Type local:Mywindow}"&gt; &lt;Setter Property="Tag" Value="{DynamicResource {x:Static SystemParameters.HighContrastKey}}" /&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="Tag" Value="True"&gt; &lt;Setter Property="Background" Value="{DynamicResource MyColor}"/&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; </code></pre> <p>and also </p> <pre class="lang-xml prettyprint-override"><code>&lt;Style TargetType="{x:Type local:Mywindow}"&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Binding="{Binding Source={x:Static SystemParameters.HighContrast}}" Value="True"&gt; &lt;Setter Property="Style" Value="{DynamicResource highContrastStyle}"/&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&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