如何使用OnPropertyChanged()方法获取静态属性
问题描述:
private static Visibility isenable;
public static Visibility IsEnable
{
get
{
return isenable;
}
set
{
if (isenable != value)
{
isenable = value;
OnPropertyChanged("IsEnable");
}
}
}
public abstract class ViewProperty : INotifyPropertyChanged, IDisposable
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = this.PropertyChanged;
if (handler != null)
{
var e = new PropertyChangedEventArgs(propertyName);
handler(this, e);
}
}
}
OnpropertyChanged()
方法是非静态的.
有什么方法可以将OnpropertyChanged
方法用于静态属性?
OnpropertyChanged()
method is a non static.
Is there any way to use OnpropertyChanged
method for static properties?
答
我使用委托找到了解决方案
公共静态EnableDelegate DelEnable =新的EnableDelegate(DelCal);
I found solution using Delegates
public static EnableDelegate DelEnable = new EnableDelegate(DelCal);
public delegate void EnableDelegate();
private void DelCal()
{
OnPropertyChanged("IsEnable");
}
private static Visibility isenable;
public static Visibility IsEnable
{
get
{
return isenable;
}
set
{
if (isenable != value)
{
isenable = value;
}
}
}
//更改值时调用委托
IsEnable = Visibility.Hidden;
DelEnable();
//Invoking delegate when changing the value
IsEnable = Visibility.Hidden;
DelEnable();