There are two almost identical situations. In the first, the DbContext context is created as a field, gets all the data from the database, and this sheet binds to the DataGrid and everything works. In the second context, DbContext is created via using , and then everything is the same, but the data that are marked as virtual in the DataGrid not displayed. Why is that ?
UPDATE. Data not marked as virtual also not displayed.
UPDATE 2 If you start the application in debug mode from the ShowData method, and wait a couple of seconds, the data is displayed as it should. If you run fast according to the debugging method, then everything is the same.
UPDATE 3. The problem is still relevant, I want to understand why.
Situation 1.
class MainVM:BaseVM { ContentStorage db = new ContentStorage(); public MainVM() { ShowData(); } private List<Storage> listStorage; public List<Storage> ListStorage { get { return listStorage; } set { listStorage = value; OnPropertyChanged(); } } private void ShowData() { var s = db.Storages.ToList(); ListStorage = s; } public MainVM() { ShowData(); } } Situation 2.
class MainVM:BaseVM { private List<Storage> listStorage; public List<Storage> ListStorage { get { return listStorage; } set { listStorage = value; OnPropertyChanged(); } } private void ShowData() { using (var db = new ContentStorage()) { var s = db.Storages.ToList(); ListStorage = s; } } public MainVM() { ShowData(); } }
Storageor are there any proxy objects? - MonkStorage. - LightnessBindingoccurs must be read into the VM objects. VM objects must live in a UI thread, in contrast to working with the base, which must be in the background thread (aka brakes). - VladD