views:

24

answers:

2

I have an SL3 that makes asynchronous calls to a data service. Basically, there is a treeview that is bound to a collection of objects. The idea is that as a user selects a specific treeviewitem, a call is made to the data service, with a parameter specific to the selected treeviewitem being passed to the corresponding web method in the data service. The data service returns data back to the SL3 client, and the client presents the data to the user.

This works well. The problem is that when users start to navigate through the treeview using the arrow keys on their keyboard, they could press the down arrow key, for example, 10 times, and 10 calls will be made to the data service, and then each of the 10 items will be displayed to the user momentarily, until finishing with the data for the most recently selected treeview item.

So - onto the question. How can I put in some form of delay, to allow someone to navigate quickly through a treeview, then, once then stop at a certain treeviewitem, a call is made to the data service?

Thanks for any suggestions.

Chris

A: 

use Rx for silverlight

funwithcoding
A: 

As suggested by funwithcoding, you could try using the Reactive Extensions for .Net (Rx), I've not used it myself but from what I hear it would do what you're after.

However if you don't feel like you want to / have time to learn Rx etc. maybe look at using a DispatcherTimer to create a slight delay in you Treeview selected event, before you call the service to retrieve the data.

Ola Karlsson
If I chose to add the delay in the selected event, wouldn't that still create the same problem, except now there will me multiple delayed calls the the web service?
Chris
Yes it would indeed. I guess what I left out to say was that, after the timer expires, you'd have to have do a check to see if that item is still the selected one in the Treeview. If it is, do the call, if not, do nothing.
Ola Karlsson