如何使用OnPropertyChanged()方法获取静态属性 [英] How to use OnPropertyChanged() method for static properties
本文介绍了如何使用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();
这篇关于如何使用OnPropertyChanged()方法获取静态属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文