WPF触发器不为空 [英] WPF Trigger not null

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

问题描述

当属性不为空时,如何在WPF中触发动作?
为空时,这是一个可行的解决方案:

How to trigger an action in WPF when the Property is not null? This is a working solution when is null:

<Style.Triggers>
    <DataTrigger Binding="{Binding}" Value="{x:Null}">

      <Setter Property="Background" Value="Yellow" />

    </DataTrigger>
</Style.Triggers>

我知道您无法扭转状况并做您需要的事情,但想知道

I know that you cant "turn around" the condition and do what you need, but want to know

推荐答案

不幸的是,你做不到。但这实际上不是必需的:您只需要在样式设置器中而不是在触发器中指定值不为null时的背景:

Unfortunately, you can't. But actually it's not necessary : you just need to specify the background for when the value is not null in the style setters, not in the trigger :

<Style.Setters>
    <!-- Background when value is not null -->
    <Setter Property="Background" Value="Blue" />
</Style.Setters>
<Style.Triggers>
    <DataTrigger Binding="{Binding}" Value="{x:Null}">

      <Setter Property="Background" Value="Yellow" />

    </DataTrigger>
</Style.Triggers>

这篇关于WPF触发器不为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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