WPF触发器不为空

编程入门 行业动态 更新时间:2024-10-27 16:24:26
本文介绍了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触发器不为空

本文发布于:2023-11-06 04:51:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1562755.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:触发器   为空   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!