做一个布尔或者可见性的最佳方式 [英] Best way to do a boolean-or-to-visibility

查看:107
本文介绍了做一个布尔或者可见性的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控件,只有至少一系列属性中的一个返回true,才能显示。我即将实现我自己的BooleanOrToVisibilityMultiConverter,但是觉得这样做一定要有更好的(而且很明显的)方式。

I have a control that i want to be visible only if atleast one of a series of properties return true. I was about to implement my own BooleanOrToVisibilityMultiConverter, but it feels like there must be a better (and completely obvious) way to do this.

请启发我!

推荐答案

是从你的模型返回一个单一的布尔值,其中包含了您的控件是否应该可见的逻辑。

The MVVM way of doing this is to return a single boolean from your model which contains the logic which works out whether your control should be visible or not.

通常如果我有这样的逻辑,因为我正在尝试表达一些域名概念,例如:

Normally if I have this kind of logic, it's because there's some domain concept I'm trying to express - for instance:


  • 这个国家/地区

  • 它已经准备好处理

  • 它还需要一些工作

  • 这是一个完整的套装

  • 全部作者被归为

  • it's in this country
  • it's ready to process
  • it still needs some work
  • it is a complete outfit
  • all authors are attributed

等。

通过保持导致的逻辑贵族的领域概念,让您更容易测试和维护。否则,您将最终在使用域名概念的地方复制同样的逻辑,而在Xaml中并不容易。

By keeping the logic which leads to the domain concept out of the Gui, you make it easier to test and to maintain. Otherwise you'll end up replicating that same logic everywhere you use the domain concept, and it's not so easy in Xaml.

这篇关于做一个布尔或者可见性的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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