I'm new at MVVM and I have a problem with updating lists.
I have 2 windows and ListViews in it. They are connected to a property "Tasks". When I add a new row to my db I need to refresh ListViews. I've done it, but only for 1 window.
adding a new row to a db table
private void OnAddTaskExecuted(object p)
{
tasks tsk = new tasks()
{
taskname = "1",
description = "",
date = DateTime.Now,
empID = 2
};
Core.db.tasks.Add(tsk);
Core.db.SaveChanges();
Tasks = new ObservableCollection<tasks>(Core.db.tasks);
//it updates only in the window from which I'm adding the row
}
viewmodel ctor
public MainWindowViewModel()
{
AddTask = new RelayCommand(OnAddTaskExecuted, p => true);
Tasks = new ObservableCollection<tasks>(Core.db.tasks);
}
So after clicking a btn I have this situation. ListView updates only in window where I click, but not in another (the new tasks is the first one)img
P.S. I have 2 same windows, I just making a new same window by btn click. That is just for a test. I'm actually creating a big project with lots of pages in it, and I need to update every Collection that have tasks in it.