DataTrigger,其中值不为空? [英] DataTrigger where value is NOT null?

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

问题描述

我知道我可以做检查,看看是否值为NULL,做一些事情似的。例如:

I know that I can make a setter that checks to see if a value is NULL and do something. Example:

<TextBlock>
  <TextBlock.Style>
    <Style>
      <Style.Triggers>
        <DataTrigger Binding="{Binding SomeField}" Value="{x:Null}">
          <Setter Property="TextBlock.Text" Value="It's NULL Baby!" />
        </DataTrigger>
      </Style.Triggers>
    </Style>
  </TextBlock.Style>
</TextBlock>

但我怎么能检查一个不的价值......为NOT NULL或不等于3?这有可能在XAML?

But how can I check for a "not" value... as in "NOT NULL", or "NOT = 3"? Is that possible in XAML?

结果:作为你的答案谢谢...我知道我可以做一个值转换器(这意味着我将在code去了,那会不会是纯粹的XAML我希望)。然而,这并回答有效地不,你不能这样做的纯XAML的问题。选择的回答,然而,可能示出的创建的那样的功能的最佳方式。好找。

Results: Thanks for your answers... I knew I could do a value converter (which means I would have to go in code, and that would not be pure XAML as I hoped for). However, that does answer the question that effectively "no" you can't do it in pure XAML. The answer selected, however, shows probably the best way to create that kind of functionality. Good find.

推荐答案

我遇到了与DataTriggers类似的限制,它似乎只能检查平等。我见过,可以帮助你最接近的事是做其他类型的不是平等其他比较的技术。

I ran into a similar limitation with DataTriggers, and it would seem that you can only check for equality. The closest thing I've seen that might help you is a technique for doing other types of comparisons other than equality.

本博客文章介绍了如何做比较,如LT,GT等在DataTrigger。

This blog post describes how to do comparisons such as LT, GT, etc in a DataTrigger.

在DataTrigger的这种限制可以通过使用一个转换器来按摩数据转换成一个特殊值,那么你可以比较各地的合作在一定程度上,如罗伯特Macnee的答复建议。

This limitation of the DataTrigger can be worked around to some extent by using a Converter to massage the data into a special value you can then compare against, as suggested in Robert Macnee's answer.

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

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