私はいくつかのクラスの静的プロパティをいくつかのコントロールにバインドしようとしています。私はいくつかの実装をtryiedましたが、それぞれがその問題を持っています静的プロパティをバインドし、INotifyPropertyChangedを実装する
すべての例は次のXAMLを使用します。
<Label Name="label1" Content="{Binding Path=text}"/>
第一のアプローチ - INotifyPropertyChangedの
public class foo1
{
public static string text { get; set; }
}
を使用していない問題があることです'text'特性が変更された場合、制御は通知されません。
第二のアプローチ - OnPropertyChangedを()メソッドは静的ではありません、それは静的メソッド内で呼ばれていますので、これはコンパイルされませんINotifyPropertyChangedの
public class foo1 : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
private static string _text;
public static string text
{
get { return _text; }
set
{
_text = value;
OnPropertyChanged("text");
}
}
}
を使用しています。
2番目のアプローチtry 2:Make OnPropertyChanged()method static => OnPropertyChanged()は静的であり、静的ではない 'PropertyChanged'イベントを使用しようとするため、これはコンパイルされません。
2番目のアプローチtry 3:make 'PropertyChanged' event static =>クラスが 'INotifyPropertyChanged.PropertyChanged'イベントを実装していないためコンパイルされません( 'INotifyPropertyChangedインターフェイスは静的ではありませんが、静的)。
この時点で私はあきらめました。
すべてのアイデア?
private static string _text;
public string text
{
get { return _text; }
set
{
_text = value;
OnPropertyChanged("text");
}
}
は、しかし、これは変更通知のみの1つのインスタンスで作成されているので、比較的無意味な結合全体を行います
私は少し異なる –