数据绑定到CLR对象问题 [英] Databinding to CLR object problem
问题描述
我在expresion blend中创建一个文本框,并将其数据绑定到名为Car的类的CarName字段。
I create a textbox in expresion blend and databind it to the CarName field of a class called Car.
在C#代码中,我想更改同一对象的CarName,所以我使用它:
In the C# code I want to change the CarName of the same object so I use this:
  ;        Car car = this._carTextBox.DataContext as Car;
car.CarName =" New Car Name";
Car car = this._carTextBox.DataContext as Car;
car.CarName = "New Car Name";
然而文本框仍然留空。
推荐答案
您的数据对象(Car)需要为数据绑定系统实现INotifyPropertyChanged以注意更改:
Your data object (Car) needs to implement INotifyPropertyChanged for the databinding system to notice the change:
http:// msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx
http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx
幸运的是,这很容易做到。
Fortunately it is easy to do.
这篇关于数据绑定到CLR对象问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!