PropertyChanged总是为空的原因可能有以下几种情况:
针对以上情况,可以采取以下解决方法:
public class MyClass : INotifyPropertyChanged
{
private string myProperty;
public string MyProperty
{
get { return myProperty; }
set
{
if (myProperty != value)
{
myProperty = value;
OnPropertyChanged(nameof(MyProperty));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
MyClass myObject = new MyClass();
myObject.PropertyChanged += MyObject_PropertyChanged;
private void MyObject_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
// 处理属性变化
}
腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云