我有以下(缩写)xaml:
<TextBlock Text="{Binding Path=statusMsg, UpdateSourceTrigger=PropertyChanged}"/>
我有一个单例类:
public class StatusMessage : INotifyPropertyChanged
{
private static StatusMessage instance = new StatusMessage();
private StatusMessage() { }
public static StatusMessage GetInstance()
{
return instance;
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string status)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(status));
}
}
private string statusMessage;
public string statusMsg
{
get
{
return statusMessage;
}
set
{
statusMessage = value;
OnPropertyChanged("statusMsg");
}
}
}
在我的主窗口构造函数中:
StatusMessage testMessage = StatusMessage.GetInstance();
testMessage.statusMsg = "This is a test msg";
我无法让文本块显示测试消息。当我通过调试监控代码时,PropertyChanged 始终为空。有任何想法吗?