我该怎么办的数据绑定在C#? [英] How can I do Databinding in c#?

查看:84
本文介绍了我该怎么办的数据绑定在C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下类


public class Car
{
   public Name {get; set;}
}

和我想以编程方式绑定这一个文本框。

and I want to bind this programmatically to a text box.

我该怎么办呢?

拍摄在黑暗中:


...
Car car = new Car();
TextEdit editBox = new TextEdit();
editBox.DataBinding.Add("Name", car, "Car - Name");
...

我得到以下错误无法绑定到属性格式名称的控制目标。

I get the following error "Cannot bind to the propery 'Name' on the target control.

我是什么做错了,我应该怎么做呢?我发现了绑定的概念有点难以把握,从网络发展的到来。

What am I doing wrong and how should I be doing this? I am finding the databinding concept a bit difficult to grasp coming from web-development.

推荐答案

您想

editBox.DataBindings.Add("Text", car, "Name");

第一个参数是要被数据绑定控件的属性的名称,第二个是数据源,第三个参数是要绑定到数据源的属性。

The first parameter is the name of the property on the control that you want to be databound, the second is the data source, the third parameter is the property on the data source that you want to bind to.

这篇关于我该怎么办的数据绑定在C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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