PivotViewer Shorts Part 2: Hide View and SortBy Buttons

By default the Silverlight PivotViewer control displays two view selection buttons and a sortby dropdown list of facet names.
Some people have expressed a wish to hide these usually because they want to replace them and control the UX with custom elements.
This short post shows how to locate the UI element for the control bar and the child elements in order to alter their visibility.
Locating the UI Elements

The flow of the code goes something like this:

  • Locate the “PART_Container” in the tree. This is a Grid control.
  • Locate the CollectionViewerView control.
  • Locate the ControlBarView control.
  • Locate the DockPanel containing the buttons.
// Locate UI Elements
Grid partContainer = (Grid)this.GetTemplateChild(“PART_Container”);
CollectionViewerView CVV = (CollectionViewerView)(partContainer).Children[0]);
Grid container = CVV.Content as Grid;
// For exposing the top control bar (title,views,sortby,slider)
ControlBarView ControlBar = ((UIElement)container.Children[2]) as ControlBarView;
DockPanel barDockPanel = (((Grid)ControlBar.Content).Children[2]) as DockPanel;
// Hide the controls
barDockPanel.Children[0].Visibility = Visibility.Collapsed; // sortby list
barDockPanel.Children[1].Visibility = Visibility.Collapsed; // view buttons
If you want to try out the code there are a few things to watch out for. You will probably want to hide the controls when the collection event CollectionLoadingCompleted fires.
You will need some internal Microsoft Pivot references and usings too. Depending upon the extent of your other customizations you will need these:
using System.Windows.Pivot;
using Microsoft.Pivot.Internal.Controls;
using Microsoft.Pivot.Internal.Model;
using Microsoft.Pivot.Internal.ViewModels;
using Microsoft.Pivot.Internal.Views;
Further things to do
This article is a brief guide to locating some visual elements of the Silverlight PivotViewer control in order to hide the view buttons and sortby facet list. It targets the developer who has already started customizing the Silverlight PivotViewer control beyond the public API and alter the UX.
Any comments or request for future topics are welcome.

2 responses to “PivotViewer Shorts Part 2: Hide View and SortBy Buttons

  1. Pingback: Xpert360 PivotViewer Blog Article Index | Xpert360 Ltd Development Blog

  2. what namespace is DockPanel in? I can’t seem to find it? Thank you.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s