前の投稿のMVVMを使用して、別のクラスのテキストブロックプロパティをUIクラスにバインドできませんでした。 Can not bind textblock property from another class to UI class using MVVMMVVMを使用して、別のクラスからUIクラスにtextblockプロパティをバインドできません。(vol。2)
私はまだtextblockプロパティをバインドすることはできませんが、textblockプロパティをバインドできない場合、PropertyChangedイベントがnullになるという新しいことが見つかりました。
(また以前の記事を参照してください)怒鳴るコードを参照してください。
public class Authentication : ViewModelBase
{
private string _ErrorStatus;
public string ErrorStatus
{
get
{
return _ErrorStatus;
}
set
{
_ErrorStatus = value;
NotifyPropertyChanged("ErrorStatus");
}
}
void Authenticate()
{
//The bellow code doesn't work.
ErrorStatus = "Access Denied.";
}
}
を怒鳴るのコードでは、のPropertyChangedがnullになります。
public class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(String info)
{
//PropertyChanged is null, so event is not called and ErrorStatus is not changed.
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
正しいコードを書く方法と、なぜPropertyChangedがnullになるのか教えてください。
ErrorStatusがUIクラス(MainPage.cs)で呼び出されたときに、ErrorStatusが正しく変更されることを既に確認しました。
ありがとうございます。しかし、それはあなたのソリューションを使用して動作しませんでした。 – okame100