【发布时间】:2012-02-22 20:47:53
【问题描述】:
技术:.NET 4、C#、WinForms、Visual Studio 2010
我正在学习数据绑定,甚至无法让一个简单的示例按预期工作。我有一个带有我要绑定的标签的表单,它显示了当前的鼠标光标坐标。
public partial class Form1 : Form, INotifyPropertyChanged
{
[Bindable(true)]
private String cursorPosition;
public String CursorPosition
{
get
{
return cursorPosition;
}
set
{
cursorPosition = value;
NotifyPropertyChanged("CursorPosition");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public Form1()
{
InitializeComponent();
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
CursorPosition = "(" + Convert.ToString(e.X) + " , " + Convert.ToString(e.Y) + ")";
}
private void NotifyPropertyChanged(String propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
从设计器中,我设置了标签的数据绑定以将 Text 属性绑定到 form1BindingSource - CursorPosition。我错过了什么?
编辑:更新了代码 sn-p。
【问题讨论】:
标签: c# .net winforms data-binding