WPF窗口上的高对比度触发 [英] High contrast trigger on a WPF window

查看:165
本文介绍了WPF窗口上的高对比度触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将触发器应用于我创建的基本WPF窗口.我可以成功地对其应用样式,但是触发器似乎不起作用.

本质上,我正在做的是在运行时将当前资源字典转储到应用程序中,并加载另一组资源字典以解决高对比度问题.它似乎正在工作,但是我正在尝试提出一种需要以高对比度模式处理的图像的解决方案.在这种特殊情况下,窗口"背景被设置为图像画笔.在高对比度模式下,我试图使用触发器将背景设置为系统颜色.

我尝试了在以下位置找到的此解决方案:http://social.msdn.microsoft.com/Forums/en/wpf/thread/ba9a379b-4f02-408c-954b-6057e6d0a1b5.似乎都不起作用.

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.

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 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.

I tried this solution i found on here: http://social.msdn.microsoft.com/Forums/en/wpf/thread/ba9a379b-4f02-408c-954b-6057e6d0a1b5. Neither seem to work.

<Style TargetType="{x:Type local:Mywindow}">
     <Setter Property="Tag" Value="{DynamicResource {x:Static SystemParameters.HighContrastKey}}" />
     <Style.Triggers>
       <Trigger
           Property="Tag"
           Value="True">
         <Setter Property="Background" Value="{DynamicResource MyColor}"/>
       </Trigger>
     </Style.Triggers>
   </Style>




还有




and also

<Style TargetType="{x:Type local:Mywindow}">
       <Style.Triggers>
           <DataTrigger
               Binding="{Binding Source={x:Static SystemParameters.HighContrast}}"
               Value="True">
               <Setter Property="Style" Value="{DynamicResource highContrastStyle}"/>
           </DataTrigger>
       </Style.Triggers>
   </Style>

推荐答案

弄清楚了.不得不对RelativeSource.Self进行绑定.为true和false添加两个触发器.忽略转换器..我需要一个用于我正在使用的图像.

Figured it out. Had to do the binding to RelativeSource.Self.. Add two triggers for true and false. Ignore the converter.. I needed one for the image I was using.

<style x:key="MyWindowKey" targettype="{x:Type test:MyWindow}" xmlns:x="#unknown">
        <setter property="Tag" value="{DynamicResource {x:Static SystemParameters.HighContrastKey}}" />
        <style.triggers>
            <datatrigger binding="{Binding RelativeSource= {x:Static RelativeSource.Self}, Path=Tag}" value="True">
                <setter property="Background" value="{DynamicResource MyWindowBrush}" />
            </datatrigger>
            <datatrigger binding="{Binding RelativeSource= {x:Static RelativeSource.Self},  Path=Tag}" value="False">
                <setter property="Background">
                    <setter.value>
                        <imagebrush imagesource="{Binding Source={x:Static test:Images.MyImage},Converter={StaticResource ResourceKey=ImageConverter}}" stretch="UniformToFill">
                        </imagebrush>
                    </setter.value>
                </setter>
            </datatrigger>
        </style.triggers>
    </style>


这篇关于WPF窗口上的高对比度触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆