Wpf 绑定到静态singleton属性时,PropertyChanged为null
有两个视图模型 BaseViewModel MainWindowsViewModel BaseViewModel是主窗口之父 和BaseViewModel具有公共as属性 问题是,当MainWindowVM更改IsLoading属性时,它不会生效 PropertyChanged为空Wpf 绑定到静态singleton属性时,PropertyChanged为null,wpf,mvvm,Wpf,Mvvm,有两个视图模型 BaseViewModel MainWindowsViewModel BaseViewModel是主窗口之父 和BaseViewModel具有公共as属性 问题是,当MainWindowVM更改IsLoading属性时,它不会生效 PropertyChanged为空 有什么解决方案吗?您正试图绑定到从公共类的IsLoading,但绑定意味着IsLoading是静态的,而不是静态的 您可能需要这样的绑定: public class Common : NotificationObje
有什么解决方案吗?您正试图绑定到从公共类的IsLoading,但绑定意味着IsLoading是静态的,而不是静态的 您可能需要这样的绑定:
public class Common : NotificationObject
{
private static Common _instance = null;
private bool _isLoading;
public bool IsLoading
{
get { return _isLoading; }
set
{
if (_isLoading != value)
{
_isLoading = value;
RaisePropertyChanged(() => IsLoading);
}
}
}
protected Common()
{
}
public static Common GetInstance()
{
if (_instance == null)
_instance = new Common();
return _instance;
}
}
您还应使用属性访问您的singleton:
{Binding Source={x:Static Common.Instance}, Path=IsLoading}
不,我不明白这个问题。可能是一堆东西。没有足够的信息来说明发生了什么。
{Binding Source={x:Static Common.Instance}, Path=IsLoading}
public static Common Instance {
get {return _instance??(_instance = new Common());}
}