使用PropertyChanged委托引发多个PropertyChanged事件
本文关键字:PropertyChanged 事件 使用 | 更新日期: 2023-09-27 18:15:05
我有一个类RuleDependency和两个属性IsNull
和ValueTypeEnabled
。我们正在使用silverlight为我们的UI,我希望有以下功能。当IsNull
属性改变时,我希望为第二个属性:ValueTypeEnabled
引发PropertyChanged
事件。请注意,这是一个部分类,作为来自web服务的类的扩展,我在引用中有IsNull
Property
,所以我不能在IsNull Property
的setter上为我的ValueTypeEnabled
RaisePropertyChanged
。我做了以下的事情:
public partial class RuleDependency
{
public RuleDependency() {
PropertyChanged += RuleDependency_PropertyChanged;
}
private void RuleDependency_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsNull") {
this.RaisePropertyChanged("IsNull");
this.RaisePropertyChanged("ValueTypeEnabled");
}
}
private bool _valueTypeEnabled;
public bool ValueTypeEnabled
{
get {
return (IsNull == null || !IsNull.Value)
}
}
}
由于未知的原因,修改IsNull property
没有引发ValueTypeEnabled
属性的事件
问题是没有调用这个部分类中的构造函数,因此该函数不会绑定到事件处理程序。我修复了它,添加了这个
dependencies[i].PropertyChanged += dependencies[i].RuleDependency_PropertyChanged;