I'm trying to understand how to use your Load On Demand funtionality, and data binding while retrieving data Asynchronous from a server.
I have found examples that show how to "load on demand" and "data bind" to observable collections but the examples get data syncronously. Those examples have the benifit of always generating the data directly in the "LoadOnDemand" event and/or having ALL the data loaded at the beginning of the tree load process then used in the event. When I say the examples are syncronous here, I mean that the data is alway exists before the "LoadOnDemand" event is finished.
I'm not sure what to do when the data will not exist at the time of the "LoadOnDemand" event and won't exist for some time after. I'm thinking that event will finish and some additional steps will need to take place to get the treeviewitem populated and expanded once that data is returned Asynchronous from the server.
We use the MVVM and MVC in our architecture. In my thoughts, I can see it working something like this but not sure how to put it together with your control and it's events. It almost seems like I need to manipulated events somehow or need a better understanding.
Let's say the treeview is bound to an observable collection;
I have found examples that show how to "load on demand" and "data bind" to observable collections but the examples get data syncronously. Those examples have the benifit of always generating the data directly in the "LoadOnDemand" event and/or having ALL the data loaded at the beginning of the tree load process then used in the event. When I say the examples are syncronous here, I mean that the data is alway exists before the "LoadOnDemand" event is finished.
I'm not sure what to do when the data will not exist at the time of the "LoadOnDemand" event and won't exist for some time after. I'm thinking that event will finish and some additional steps will need to take place to get the treeviewitem populated and expanded once that data is returned Asynchronous from the server.
We use the MVVM and MVC in our architecture. In my thoughts, I can see it working something like this but not sure how to put it together with your control and it's events. It almost seems like I need to manipulated events somehow or need a better understanding.
Let's say the treeview is bound to an observable collection;
- Data is loaded into the silverlight tree view root upon loading the component. (which would happen asynchronously).
- At this point let's say that their are 5 "root" nodes in the tree.
- At this point the observable collection contains only "root" nodes. No data has been queried for any children.
- None of the "root" children are expanded at this point and there is no child data yet loaded into the observable collection. The user clicks a "root" node and wants to expand it to show the "children".
- We will need to request the data from the web server.............
- The “LoadOnDemand” event is trigged (per you examples).
- This is where I'm not sure what to do based on the existing examples..........
- Upon, the “LoadOnDemand” event triggering, we would call our ViewModel and tell it to request data from the Model. (Through mechanism that don't pertain here, the server side code will query a database and send back data. At a later point, the Model will eventually send the data back to the ViewModel. )
- At this point the “LoadOnDemand” event won’t have new "child" data from the server because it’s coming asynchronously at a later point.
- Which means the “LoadOnDemand” event will exit without having the "child" data.
- At some point the data will be returned from the server and placed somewhere. Proably in the observable collection which needs to update the tree view "root" with it's children, render those children and expand the parent correctly.
- This is what I'm not undestanding how does #11 get tied all together to make it work happily.
Can you provide a sample solution? A solution that doesn't have the data at the time the "LoadOnDemand" event is triggered and finished? Then sometime after that the data exists and the root gets populated, expanded, and all the children show? Our tree will have many levels but a basic example will help me understand what to do.
How does the Asynchronous data get loaded into the correct tree view "root" with it's children, render those children and expand the parent correctly.
An example of this would help me out tremendously. Are their any examples of doing this asynchronously?