I have spent a bunch of time trying to figure out why the control bound to Items in my view was not refreshing. Here is the scenario:
1 - Data is loaded in Master VM before activating ViewModel (Conductor.Collection.OneActive)
2 - Data is not loaded in Master VM before activating ViewModel (Conductor.Collection.OneActive)
When I activate the childVM the VM calls a MasterVM.ChildVMIsActivate( childVM ) method and the Master VM supplies refreshed data (IEnumerable<IScreen>). This works great. However if the Master VM hasn't loaded the data then I need
to delay until the data is loaded.
What I did is check to see if the MasterVM is ready (bool flag) to load data. If it is, I call the method above, if it isn't I subscribe to the property changed and keep listening for that flag to be true. I also set the IsBusy flag
to true so that my view is disabled. When the property changes I recall the method above, load my data, and then unsubscribe from the event. This works great and my data is loaded.
However here is where I ran into issues:
In my loadData event, where I am populating Items I thought I would be efficient and use IsNotifying true/false
public void InitializeData(IEnumerable browserListItems)
var isBusy = IsBusy;
IsBusy = true;
foreach (var browserItem in browserListItems) ((IBrowserListItemViewModel) browserItem).SetBrowserListViewModel(this);
Items.IsNotifying = false;
Items.AddRange(browserListItems as IEnumerable<TBrowserListItemViewModel>);
Items.IsNotifying = true;
NotifyOfPropertyChange(() => Items);
IsBusy = isBusy;
Under scenario one this worked fine however under scenario two it would not rebind Items. I could put a breakpoint on Items and see there was data there.
I tried all sorts of ActiveThis, OnNotifyPC(Items) etc. What did work was deactivating and re-activating. I tried numerous UI controls that I bound to ItemSource
to see if that was the issue.
Finally I removed the Items.IsNotifying lines and everything was fine.
So - could someone please explain to me what may have been happening and when would I want to use IsNotifying? In my scenario to test the delayed load I am
dropping in 2300+ VM into items.