private void Button_Click(object sender, RoutedEventArgs e)
{
this.Dispatcher.Invoke(() =>
{
EditTheCollection();
});
}
public void EditTheCollection()
{
viewModel.Data[0].YValue=10;
}
}
public class Model :INotifyPropertyChanged
{
public double XValue { get; set; }
private double yValue;
public double YValue
{
get { return yValue; }
set { yValue = value; OnPropertyChanged("YValue"); }
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}
public class ViewModel
{
public ViewModel()
{
GenerateData();
}
private static object _lock = new object();
public void GenerateData()
{
Data = new ObservableCollection<Model>();
Random rd = new Random();
for (int i = 0; i < 6; i++)
{
Data.Add(new Model()
{
XValue = i,
YValue = rd.Next(0, 50)
});
}
BindingOperations.EnableCollectionSynchronization(Data, _lock);
}
private ObservableCollection<Model> data;
public ObservableCollection<Model> Data
{
get { return data; }
set { data = value; }
}
} |
Hi Tom,We have analyzed the reported problem with our source, it occurs due to non-UI thread trying to access the UI thread in our source.So, we recommend, you to use the solution provided in our previous update.Thanks,Muneesh Kumar G.