Question with Items.IsNotifying

Topics: Framework Services, Getting Started
May 19, 2011 at 7:34 PM

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.






May 24, 2011 at 4:00 PM

just bumping this as a slew of dicussions happened right after I posted... any thoughts anybody?

May 24, 2011 at 4:16 PM

Instead of 

NotifyOfPropertyChange(() => Items);

Do this:

May 24, 2011 at 6:32 PM

Thank you - that did the trick!

Is there any easy explanation why?



May 24, 2011 at 6:36 PM
Edited May 24, 2011 at 6:37 PM

NotifyOfPropertyChange(() => Items); tells the databinding system that the whole property changed. While the Refresh method I added, tells the binding system that the collection contents have been reset. 
You would think that the databinding system would treat these as almost the same. But, the databinding system tries to be smart sometimes and when you say that a property has been refreshed, if it's still the same instance, the binding won't refresh. 
It's just one of those Xaml things.