In the examples for coding with the MVVM pattern and WPF binding, they use INotifyPropertyChanged
when it's a single value and ObservableCollection
when it is a list of values.
I've also read, you cannot use static variables with INotifyPropertyChanged
, but you can with ObservableCollection
. I'd like to bind to a static variable.
The easiest (to me at least) workaround, is to use an ObservableCollection
and always just use and bind to index 0. Is this appropriate to do? Is there any benefit to using INotifyPropertyChanged
instead of an ObservableCollection
?
For example: This seems to be the simplest workaround:
public static ObservableCollection<int> MyValues { get; set; }
<TextBox Text="{Binding MyValue[0]}">
For wanting to do this:
private static int _myValue;
public static int MyValue //does not work
{
get { return _myValue; }
set { _myValue = value; OnPropertyChange(); }
}
<TextBox Text="{Binding MyValue, UpdateSourceTrigger=PropertyChanged}">