如何将Control.Enabled数据绑定到!(field)? [英] How do I data bind Control.Enabled to !(field)?

查看:54
本文介绍了如何将Control.Enabled数据绑定到!(field)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个(varchar)字段Foo,只有在(bit)Bar not true时才能指定。我希望Bar为true时,显示Foo的文本框禁用-本质上是 FooBox.Enabled =!isBar 。我正在尝试做类似的事情

I have a (varchar) field Foo which can only be specified if (bit) Bar is not true. I would like the textbox in which Foo is displayed to be disabled when Bar is true -- essentially, FooBox.Enabled = !isBar. I'm trying to do something like

FooBox.DataBindings.Add(new Binding("Enabled", source, "!isBar"));

当然,这里的爆炸会引发异常。我也尝试过类似 isBar!= true或 isBar<> true的构造,但是没有任何作用。我在这里树错树了吗?

but of course the bang in there throws an exception. I've also tried constructs like "isBar != true" or "isBar <> true", but none work. Am I barking up the wrong tree here?

推荐答案

我前一段时间尝试做这样的事情,我可能会想出最好的办法

I tried doing something like this a while ago and the best I could come up with was either

a)将源类更改为还具有NotBar属性并绑定到该属性

a) Changing the source class to also have a NotBar property and bind to that

b )在具有NotBar属性的源周围制作一个愚蠢的包装器类,并绑定到该类。

b) Make a dumb wrapper class around source that has a NotBar property and bind to that.

这篇关于如何将Control.Enabled数据绑定到!(field)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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