I am using a ObservableCollection to store the Environment Variables of Windows.
class VariableVieWModel
{
ObservableCollection vars
You need to implement INotifyPropertyChanged
for your VariableVieWModel to refresh your target object bindings. You just have to do this way -
class VariableVieWModel : INotifyPropertyChanged
{ .
.
public ObservableCollection<VariableModel> Variables
{
get
{
return vars;
}
set
{
if(vars!=value)
{
vars = value;
OnPropertyChanged("Variables");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
}
You haven't modified the ObservableCollection, only replaced it.
You should implement INotifyPropertyChanged
and call PropertyChanged
in the Variables
property setter.
BTW it's common in MVVM implementations to have a base class for your ViewModel:
class VariableViewModel : ViewModelBase
and implement common functionality such as INotifyPropertyChanged
in the base class to avoid duplication of code.
The problem is, that probably your VariableModel does not implement INotifyPropertyChanged. Through ObservableCollection, only changes to the collection are reported, not changes of the contained objects.
Here you will find some implementation possibilities.