私はバインドしているDataGrid
ComboBox
の変更をINotifyPropertyChanged
が更新する静的プロパティを作成しようとしています。INotifyPropertyChangedを使用する静的プロパティ。 C#
私はこのエラーを取得しています、
エラーCS0026キーワード私の検索で「この」、静的プロパティでは有効ではありません静的 方法、または静的フィールド
Why can't you use the keyword 'this' in a static method in .Net?しかし、すべてを通過した後でさえ、私はまだこれを動作させる方法を理解できません。
しかし、私が変更するものは、静的なプロパティを作成しようとしていることを否定するだけですINotifyPropertyChanged
???
private static List<string> _nursingHomeSectionListProperty;
public static List<string> NursingHomeSectionListProperty
{
get { return _nursingHomeSectionListProperty; }
set
{
_nursingHomeSectionListProperty = value;
NotifyStaticPropertyChanged();
}
}
とプロパティは、ハンドラ変更
public static event PropertyChangedEventHandler StaticPropertyChanged;
public static void NotifyStaticPropertyChanged([CallerMemberName] string propertyName = null)
{
StaticPropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
そして、私は非静的プロパティのプロパティ変更されたハンドラを使用していますどのように以下のコードがある、
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
私はあなたのモデルで静的な特性が必要な理由を知りませんが、 'Invoke'の最初の引数は送信者です。単純な 'new object()'が実行します – Alex
また、なぜ代理人を使用していますか? raiseメソッドNotify ...を呼び出して名前を付け、Onにしないでください。 – Sefe
@Sefe? '.'演算子のためです。メソッドの名前は無関係です。 – Clemens