Geeks With Blogs


Timmy Kokke's Blog

↑ Grab this Headline Animator

Timmy Kokke at Blogged
Timmy Kokke …just sorting my bubbles…

PivotViewer series

  1. Building your first PivotViewer application
  2. Runtime PivotViewer collection creation
  3. PivotViewer - Working with Facets
  4. Handling PivotViewer events
  5. PivotViewer - Custom actions
  6. PivotViewer and MVVM


Today I would like to go into a little detail about the events used in the PivotViewer control for Silverlight. If you haven’t worked with the PivotViewer yet you might want to read the getting started tutorial I wrote earlier first.


The CollectionLoadingCompleted event is fired when loading of the collection is completed. 


The CollectionLoadingFailed event is raised when an error occurs when loading a collection. The event uses gets an instance of the CollectionErrorEventArgs class when it is fired. This class contains two properties.

The first is ErrorCode. This property is of the enum type CollectionError and contains two values: DownloadError and ParsingError.

ErrorCode equals DownloadError when there was an error downloading the collection. For example if the URL used in the LoadCollection method is wrong. The ErrorCode contains the ParsingError value when there is an issue with the .CXML file which prevents it from being parsed. For example a typing error in the .CXML.

The second property used in the CollectionErrorEventArgs class is Exception. This property contains the exception thrown by he PivotViewer control. This exception can provide very useful information when building runtime collections.


This event is fired when an item in the PivotViewer is double clicked. The event is given a ItemEventArgs object. The ItemEventArgs class contains 1 property, ItemId. This string contains the ID of the items that is clicked. You can use this ID to get the whole item by calling the GetItem method on the PivotViewer control.

private void Pivot_ItemDoubleClicked(object sender, ItemEventArgs e)
    PivotItem item = Pivot.GetItem(e.ItemId);
    // insert something useful to do with the item here
    // like showing a popup with more info.





When the end-user click on a facet of the link type this event is fired by the PivotViewer control. The URL is passed to the event through the LinkEventArgs. The navigation itself isn’t performed by the PivotViewer. You’ll have to handle that yourself. The code below shows an example of that. It checks if the URL that is clicked ends with .CXML. In that case the URL is used to load a new collection. Otherwise the user will be directed to the target URL.

private void Pivot_LinkClicked(object sender, LinkEventArgs e)
    Uri targetUrl = e.Link;
    if (targetUrl.LocalPath.EndsWith(".cxml", 
        //If the link is to CXML, show it in this PivotViewer.
        Pivot.LoadCollection(targetUrl.AbsoluteUri, string.Empty);
        //Otherwise open the URL in a new window
        HtmlPage.Window.Navigate(targetUrl, "_blank");






The ItemExecutedEvent is raised when the end-user clicks on a Custom Action. Support for this isn’t fully implemented in this version of the PivotViewer control. In the next tutorial I’ll show you how to use custom actions and how they are handled using this event.


There aren’t that many events in the PiverViewer control. But it’s good to know which ones are there and how to use them.

The next tutorial will be about Custom Actions. To be the first to know when it is released you can subscribe to the RSS-feed or follow me on twitter.



Technorati Tags: ,



kick it on

Shout it

Posted on Friday, August 27, 2010 10:39 PM Silverlight , dotnetmag , PivotViewer | Back to top

Comments on this post: Handling PivotViewer events

# PivotViewer and MVVM
Requesting Gravatar...
patiently awaiting .. PivotViewer and MVVM
I have a question:
I am loading around 3 thousand files and the load time is not acceptable.What I am dong wrong? Do I need smaller pictures or a different method of loading. Kind of stuck on this.
Left by Kate on Sep 22, 2010 9:03 PM

# re: Handling PivotViewer events
Requesting Gravatar...
It depends on how you've created your images. 3000 images won't be a problem if the imagecollection is made with deepzoom. Generating 3000 images at runtime is not going to work.

Another thing that might speed things up a little is to start the pivotviewer with a default filter. You can do this by setting the ViewerState on the LoadCollection method. more info on this can be found here:
Left by timmy kokke on Sep 22, 2010 10:07 PM

# re: Handling PivotViewer events
Requesting Gravatar...
Thanks for the clear tut, Silverlight is growing on me but tutorials for it aren't as easy to find as flash!
Left by Gary Corbett on Apr 19, 2011 3:13 AM

# re: Handling PivotViewer events
Requesting Gravatar...
How to hide or show a tile?
Left by vasundradevi on May 26, 2011 11:55 AM

Your comment:
 (will show your gravatar)

Copyright © Timmy Kokke | Powered by: