本文介绍了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触发器不为空
发布评论