Click here to Skip to main content
15,881,882 members
Articles / Programming Languages / C#

Building Your First PivotViewer Application

Rate me:
Please Sign up or sign in to vote.
4.50/5 (5 votes)
23 Aug 2010CPOL2 min read 28.7K   12   2
Geting started with the Silverlight PivotViewer

Introduction

If you haven't had a chance to look at the new PivotViewer control for Silverlight, have a look here or here. The PivotViewer enables visitors of your website to search large amounts of data very easily. The control takes a lot of work out of your hands. Basically, you tell it to load a collection and the PivotViewer takes care of everything else. Like adding controls to enter search and sort criteria. It uses DeepZoom to show large amounts of images and animate between states.

Getting Started

Before you can start coding, you have download the control itself. The Silverlight control can be downloaded from the PivotViewer section on Silverlight.net. You also need the Silverlight Toolkit which can be found here.

Your First PivotViewer

To get your first PivotViewer control up and running, create a new Silverlight project in Visual Studio and add references to all 5 PivotViewer assemblies to the Silverlight project. These assemblies can be found in C:\Program Files\Microsoft SDKs\Silverlight\v4.0\PivotViewer\Jun10\Bin or C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\PivotViewer\Jun10\Bin on 64bit system.

In MainPage.xaml, add an XML namespace definition for the System.Windows.Pivot namespace and add the control to the LayoutRoot grid.

XML
<UserControl x:Class="PivotViewerGettingStarted.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:Pivot="clr-namespace:System.Windows.Pivot;assembly=System.Windows.Pivot">
  <Grid x:Name="LayoutRoot" Background="White">
    <Pivot:PivotViewer x:Name="Pivot"/>
  </Grid>
</UserControl> 

Getting data in the PivotViewer control has to be done in CodeBehind. The PivotViewer contains a method LoadCollection which takes a URL to a .CXML file. This file can be stored anywhere on the web and can be accessed as log as there is a valid ClientAccessPolicy.xml file available. For demonstration purposes, there are a couple of collections available on the GetPivot.com site (at the end of this tutorial, I’ve added a list of these). I’ve used the AMG Movies Collection in this case.

The LoadCollection method also needs a value for the state. Often this value is set to string.Empty.

C#
public MainPage(){
  InitializeComponent();
  Pivot.LoadCollection(
    "http://content.getpivot.com/collections/amg/Top_Movies.cxml"
    ,string.Empty);
}

Take a look at the control running here.

What’s Next

While using the collection on GetPivot.com can be vary useful for demonstrations or learning how to develop with the PivotViewer, you won't use these collections in a real application. You will have to create a collection of your own. Have a look at this section of GetPivot.com about the Excel extension to create a collection.

Another way to create a collection is to let your program take control and build collection runtime. I will explain this in my next tutorial.

If you can’t wait and want to learn more, read the developer section on www.getpivot.com.

Other Example Sources

On the GetPivot.com site, there are a few more .CXML collections to try in your applications:

PivotViewerExample.png

License

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


Written By
Software Developer (Senior) Velicus B.V.
Netherlands Netherlands
Microsoft MVP Client Dev . Founder of http://StoreAppsUG.nl, the Dutch Windows Store apps and Windows Phone apps usergroup. XAML / HTML5 developer. Writer. Composer. Musician.

Twitter
@Sorskoot

Awards / Honers
• October 2010,2011,2012,2013: Awarded Microsoft Expression Blend MVP
• June 2009: Second Place in the WinPHP challenge
• February 2009: Runner-up in de Mix09 10k Challenge
• June 2008: Winner of the Microsoft expression development contest at www.dekickoff.nl

Bio
I started programming around 1992, when my father had bought our first home computer. I used GWBasic at that time. After using QBasic and Pascal for a few years I started to learn C/C++ in 1996. I went to the ICT Academy in 1997 and finnished it in 2002. Until December 2007 I worked as a 3D specialist. Besides modelling I worked on different development projects like a 3D based Scheduler and different simultion tools in C# and Java. Though out the years I've gained much experience with ASP.NET, Silverlight, Windows Phone and WinRT.

Comments and Discussions

 
GeneralMy vote of 2 Pin
TRW13-Oct-11 17:41
TRW13-Oct-11 17:41 
GeneralBI Example Pin
Mycroft Holmes9-Nov-10 14:44
professionalMycroft Holmes9-Nov-10 14:44 
Timmy

Do you have a link to a decent BI example.

I look forward to working through your article once I have sold the business on the idea!
Never underestimate the power of human stupidity
RAH

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.