Async LazyLoad child collection problems WPF/MVVM

Async LazyLoad child collection problems WPF/MVVM

Old forum URL: forums.lhotka.net/forums/t/10266.aspx


Kevin Fairclough posted on Friday, April 15, 2011

Ref: http://forums.lhotka.net/forums/p/9824/46131.aspx#46131

Hi

Background:

We are trying to hook up a UI to a root object with lazy collections.  The main UI has a popup UI with a separate ViewModel which is fed the child collection therefore the Model property of the VM is set manually for the child.  We want the busy spinner to be inside the child popup view.

 

Is there a snippet for the correct way to async lazy load a child object?

When calling OnPropertyChanged(ChildProperty) it marks the root as dirty.  I cannot remove this as the test wont know when the property has finished loading.  Is there an OnChildLazyLoaded I can call? 

Regarding the busy spinner, MarkBusy & MarkIdle must be required but this marks the root as busy not the child collection, so the spinner is in a different context, i.e. the center of the screen not in the center of the popup.

Also it doesn't work first time in InvalidOperationException  "Property get not allowed", similar to : http://forums.lhotka.net/forums/t/10264.aspx

Many Thanks

Kevin

 

RockfordLhotka replied on Friday, April 15, 2011

OnPropertyChanged doesn't mark an object as dirty. Only MarkDirty does that. OnPropertyChanged only raises the PropertyChanged event.

There's no real way to mark the child object as busy, because the whole point is that you are retrieving the child object. It might be busy - but it would be busy on the server as it is being loaded, and the client won't know one way or the other until it arrives on the client and is set into the property field.

In other words, the only object the client has access to during the load process is the parent object, so that's the only thing you can mark as busy.

Kevin Fairclough replied on Friday, April 15, 2011

My mistake, I've found the bug in our code regarding Dirty problem.

What we have done for now is, as we are manually setting the Model property in the ChildViewModel we also manually set the IsBusy in the ChildViewModel this gives us the spinner in the correct place.

For some reason I was under the inpression that OnPropertyChanged for the child list would be fired if and when the list contents change hence we couldn't use that to tell first load.

Thanks

 

Kevin Fairclough replied on Friday, April 15, 2011

The InvalidOperationException in GetProperty was a problem with the Getter not returning null after initiating async load call.  It was attempting to return a non initialized property, GetProperty(ImagesProperty) see first link REF link for correct way to define lazy async property.

Kevin

RockfordLhotka replied on Friday, April 15, 2011

I should also point out (shameless plug Smile ) that the Using CSLA 4 ebook series includes async lazy load code/discussion.

Copyright (c) Marimer LLC