Ho il seguente (abbreviato) XAML:evento PropertyChanged sempre nullo
<TextBlock Text="{Binding Path=statusMsg, UpdateSourceTrigger=PropertyChanged}"/>
Ho una classe Singleton:
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");
}
}
}
E nella mia finestra principale costruttore:
StatusMessage testMessage = StatusMessage.GetInstance();
testMessage.statusMsg = "This is a test msg";
Non riesco a ottenere il blocco testo per visualizzare il messaggio di prova. Quando controllo il codice tramite debug, PropertyChanged è sempre nullo. Qualche idea?
Dove si fa a impostare il vostro DataContext con un'istanza StatusMessage? –