我有一个类RuleDependency和两个属性IsNull和ValueTypeEnabled。我们正在使用silverlight为我们的用户界面,我希望有以下功能。当IsNull属性更改时,我希望为第二个属性ValueTypeEnabled引发PropertyChanged事件。请注意,这是一个分部类,作为来自for服务的类的扩展,并且我在引用中只有IsNull Property,所以我不能在IsNull Property的RaisePropertyChanged方法上为我的ValueTypeEnabled设置。我做了以下工作:
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属性的事件。
发布于 2016-10-27 16:15:26
问题是这个分部类中的构造函数没有被调用,因此该函数不会绑定到eventhandler。我修复了它,添加了这个
dependencies[i].PropertyChanged += dependencies[i].RuleDependency_PropertyChanged;当使用对象时。
https://stackoverflow.com/questions/40278776
复制相似问题