Silverlight PivotViewer – Add Collection To Your Silverlight Application
Silverlight PivotViewer – Add Collection To Your Silverlight Application
In my last post Silverlight Pivotviewer – The Full Guide was about Silverlight PivotViewer introduction and how to create your own collection to group large amount of data.
In this post I’ll show how to add your Pivot Collection to your Silverlight Application.
Gettings Started
1. Create new Silverlight Application
2. Add reference to “System.Windows.Pivot.dll” located under
C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\PivotViewer\Jun10\Bin\
3. Add Pivot name space to your Xaml file –>
xmlns:pivot="clr-namespace:System.Windows.Pivot;assembly=System.Windows.Pivot"
4. Add Pivot Viewer Control
<!-- The PivotViewer control -->
<pivot:PivotViewer Name="PivotViewerControl" Grid.Column="0"
ItemDoubleClicked="PivotViewerControl_ItemDoubleClicked">
</pivot:PivotViewer>
5. Add collection .cxml file and the files folder to your ClientBin (or if you want you can upload all under hosting service).
6. Load collection using this method - PivotViewerControl.LoadCollection(MauritiusCollectionUri, "");
7. I’ve add an event for double clicking on Collection Items, so when you double click and new browser
will open with the item link.
8. You’re Done! – Download Demo Project
Full Code Example:
private static readonly string MauritiusCollectionUri = "http://localhost:42912/ClientBin/Mauritius.cxml";
public MainPage()
{
InitializeComponent();
//Load your collection
PivotViewerControl.LoadCollection(MauritiusCollectionUri, "");
}
private void OpenLink(string linkUri)
{
HtmlPage.Window.Navigate(new Uri(linkUri, UriKind.RelativeOrAbsolute), "PivotViewerSampleTargetFrame");
}
//When double clicking an item I want to open a new browser with item link.
private void PivotViewerControl_ItemDoubleClicked(object sender, ItemEventArgs e)
{
PivotItem piv_item = PivotViewerControl.GetItem(e.ItemId);
if (!string.IsNullOrWhiteSpace(piv_item.Href))
{
PivotViewerControl.CurrentItemId = e.ItemId;
OpenLink(piv_item.Href);
}
else
{
MessageBox.Show("No Web Page...");
}
}
Download Demo Project
You want more? Just send me an email and more about Silverlight PivotViewer will arrive.