Binding static property and implementing INotifyPropertyChanged

前端 未结 3 1231
温柔的废话
温柔的废话 2021-01-06 07:54

I\'m trying to bind a static property of some class to some control. I\'ve tryied a few implementation but each has its problem:

All examples use the next XAML:

3条回答
  •  醉酒成梦
    2021-01-06 08:42

    I'd suggest you just have an instance-property return your static property like this:

    private static string _text;
    public string text
    {
        get { return _text; }
        set
        {
            _text = value;
            OnPropertyChanged("text");
        }
    }
    

    However this makes the whole binding comparatively pointless since change notifications are only created in one instance of the class and not every instance. Thus only bindings which bind to the property on the specific instance on which it was changed will update.

    A better method would be using a singleton as can be seen here.

提交回复
热议问题