Click here to Skip to main content
15,887,214 members
Articles / Silverlight / Silverlight4

Reloading a Collection in the PivotViewer

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
1 Feb 2011CPOL2 min read 9.8K   1  
Reloading a Collection in the PivotViewer

I discovered an interesting tidbit when working on the code for my upcoming PivotViewer series (you can find the code on CodePlex at http://tonyc.me/pvles). It seems that you can't reload the current collection from the server.

First off, I noticed an absence of any sort of “Reload” or “Refresh” method to make this process easy. So I began to do a little research and tried the following:

To begin with, I simply called LoadCollection() and passed in the Uri. I promptly noticed that nothing happened. Hmmm… So on to the next step.

If you are familiar with the LoadCollection() method, then you might have noticed a default viewerState as the second argument. The viewer state is a lot of fun and I will dig into that in another post. However, for this issue, I was hoping changing up the viewer state would fire off a refresh. Nope. Strike two.

So now I decided to bring out the big guns, .NET Reflector by Red-Gate, to see if I could see what is going on. By the way, it’s a great tool to have as a .NET developer and I highly recommend it. So I did a little digging, and what do you know, I found the issue.

The PivotViewer is simply trying to be efficient really. When you pass in a Uri, it compares it with the existing collection to see if it is the same. If it is, it simply does not do a reload to keep from having to make another trip to the server to update the data and interrupt the user’s experience.

Ah ha! So now we just need to change the Uri, right? My first attempt was to simply add a hash tag with a counter. So my attempts looked something like this:

First attempt:

Second attempt:

Well, it seems that the PivotViewer was smarter than me and realized it was the same Uri and ignored the new Uri. So I took it a step further and found a working solution. It seems that it will consider a change in the querystring as a new Uri. So the final working solution looks like this:

First attempt:

Second attempt:

Bingo! I nicely reloaded collection.

If you find yourself needing to refresh the collection of the PivotViewer and can't seem to make it refresh, then this should get you up and running.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
President Champion DS
United States United States
Tony Champion is a software architect with over 16 years of experience developing with Microsoft technologies. As the president of Champion DS and its lead software architect, he remains active in the latest trends and technologies, creating custom solutions on Microsoft platforms. Tony is an active participant in the community as a Microsoft MVP, international speaker, published author, and blogger. He focuses on a wide range of technologies from web solutions such as HTML5, JavaScript, Silverlight to client platforms for Windows Phone and Windows 8. He can be found on his blog at tonychampion.net and on twitter at @tonychampion.

Comments and Discussions

 
-- There are no messages in this forum --