You need add two parts for your project:
Part1 :Add NotifyObject.cs
public class NotifyObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Part2 : Make the MainWindowViewModel.cs inherits from NotifyObject,delete public ObservableCollection<User> Users { get; set; } and add like below:
class MainWindowViewModel:NotifyObject
{
//delete public ObservableCollection<User> Users { get; set; }
private ObservableCollection<User> _users;
public ObservableCollection<User> Users
{
get { return _users; }
set
{
if (_users != value)
{
_users = value;
RaisePropertyChanged("Users");
}
}
}
Then you can get the data in the main UI like this: