C# - 可以将数据绑定在值和表达式之间吗? [英] C# - Can I Data Bind between a value and an expression?
问题描述
如何使用数据绑定?
提前感谢
添加
我问过这个,每次在列表中添加或删除项目时,请尽量避免在代码列表中检查Count。但是如果没有解决方案,那么我将继续这样做。
创建一个DTO(数据传输对象)暴露您打算绑定到UI元素的所有数据。在DTO中创建一个属性(使用适当的名称):
public bool ButtonVisible
{
get {return myListCount!= 0;
}
添加一个 BindingSource
到您的表单,并将其设置为您的DTO类型的 DataSource
。
点击按钮,转到属性。展开 DataBindings 节点,然后单击高级。
向下滚动左侧窗格中的列表,然后选择可见。设置它绑定到您的财产暴露于BindingSource ..
I have a List and a Button. When the Lists Count == 0, I would like the button Visibility to = false.
How do I do this using Data Binding?
Thanks in advance,
Added
I have asked this so that I can try to avoid checking the Count on the list in code every time I add or remove an item to or from the list. But if there is no solution then I will continue to do it that way.
Create a DTO (Data Transfer Object) that exposes all your data that you intend to bind to UI elements. Create a property in the DTO (with an appropriate name):
public bool ButtonVisible
{
get { return myListCount != 0; }
}
Add a BindingSource
to your form and set it's DataSource
to your DTO type.
Click on the Button, goto Properties. Expand the DataBindings node, and click Advanced.
Scroll down the list in the left hand pane, and select Visible. Set it's binding to your property exposed vis the BindingSource..
这篇关于C# - 可以将数据绑定在值和表达式之间吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!