Silverlight 之 INotifyPropertyChanged

NotifyPropertyChanged 接口用于向客户端(通常是执行绑定的客户端)发出某一属性值已更改的通知。

例如,考虑一个带有名为 FirstName 属性的 Person 对象。 若要提供一般性属性更改通知,则 Person 类型实现 INotifyPropertyChanged 接口并在 FirstName 更改时引发 PropertyChanged 事件。

若要在将客户端与数据源进行绑定时发出更改通知,则绑定类型应具有下列任一功能:

  • 实现 INotifyPropertyChanged 接口(首选)。

  • 为绑定类型的每个属性提供更改事件。

不执行上述这两个功能。

 实例代码:

View Code
 public class BookInfo : ViewModel
{
private string _name;
private int _count;
private DateTime _publishDate;
public string Name
{
get
{
return this._name;
}

set
{
this._name = value;
this.RaisePropertyChanged("Name");
}
}

public int Count
{
get
{
return this._count;
}

set
{
this._count = value;
this.RaisePropertyChanged("Count");
}
}

public DateTime PublishDate
{
get
{
return this._publishDate;
}

set
{
this._publishDate = value;
this.RaisePropertyChanged("PublishDate");
}
}

public class ViewModel : IViewModel
{
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

protected void RaisePropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}

/// <summary>
/// 视图模块接口
/// </summary>
/// <!--2010年8月14日-->
public interface IViewModel : System.ComponentModel.INotifyPropertyChanged
{
}



转载于:https://www.cnblogs.com/Adhere/archive/2011/12/08/2280703.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值