PivotViewer, Silverlight

Handling PivotViewer events

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: silverlight,pivotViewer




kick it on DotNetKicks.com


Shout it


  1. Ok, I think it goes in MainPage.xaml.cs , but I’m getting an “Expected class, delegate, enum, interface, or struct” from the void.

  2. Ok, I was getting the error because I hadn’t put it in a class. I made up a class name and no longer get any errors, but the resulting xap’s behavior didn’t change. Links are still not clickable.

  3. Hi, I am using Pivotviewer to display Images in SharePoint 2010, its working fine in local machine but not working on production machine, I am getting blank page.. with the status counting 0 to 100%.. what could be the reason. I am using Sharepoint list to store the images & giving the same in the Pivotviewer as a source

Leave a Reply

Seo wordpress plugin by www.seowizard.org.
%d bloggers like this: