我想大部分的WPF和SL开发者都应该对INotifyPropertyChanged这个接口再熟悉不过了。
2013-01-24 15:57 呆河马 阅读(211) 评论(0) 编辑 收藏 举报#region Copyright PwC GDC Sep. 2010 // // All rights are reserved. Reproduction or transmission in whole or in part, in // any form or by any means, electronic, mechanical or otherwise, is prohibited // without the prior written consent of the copyright owner. // // Author:John Shao Sep.20.2010 // #endregion using System.ComponentModel; namespace PwC.FCPA.ViewModel { /// <summary> /// ViewModel base class and implement INotifyPropertyChanged interface /// </summary> public abstract class ViewModelBase : INotifyPropertyChanged { #region INotifyPropertyChanged /// <summary> /// Property Change Event /// </summary> public event PropertyChangedEventHandler PropertyChanged; /// <summary> /// Implement INotifyPropertyChanged's function, when binding data in UI control /// this function will invoke PropertyChanged event. /// </summary> /// <param name="propertyName">Property Name</param> public virtual void NotifyPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } #endregion } }
当我们向UI传递属性变化的通知并更新客户端UI时就必须应用到它。(这里插一句,当一个集合中的项改变时我们则需要使用ObservableCollection<T>泛型集合)