Introduction
Adding tooltips to the left side filter pane not surprisingly requires the use of a customized PivotViewer control:
You should be familiar with the following line of code to get the CollectionViewerView from earlier blog posts and samples.
CollectionViewerView cvv =
((CollectionViewerView)((Grid)
this.GetTemplateChild(“PART_Container”)).Children[0]);
If you are not familiar with this then I would recommend taking the time to work through the other posts in this series and build up you portfolio of PivotViewer customization skills.
Locating the UI Elements and attaching ToolTips
Tooltips can be set on controls in code behind using the ToolTipService. Normally you might use the ToolTip attached property of the ToolTipService class and the ToolTip control in your XAML.
The flow of the code goes something like this:
- Locate the “PART_FacetPane” in the tree. This is a CustomAccordian control.
- Locate the CustomAccordianItem‘s ( == facets)
- … under each item is a FacetCategory control to find the facet category name.
- … use the TooltipService to set custom tooltips on the CustomAccordianItem‘s
FilterPaneView FPV = (FilterPaneView)PivotViewer.CollectionView.FindName(“PART_FilterPane”();
CustomAccordion FacetPane = (CustomAccordion)FPV.FindName(“PART_FacetPane”);
StackPanel itemsHost = (StackPanel)FacetPane.GetItemsHost();
for (int nitem = 0; nitem < itemsHost.Children.Count; nitem++)
{
CustomAccordionItem item = (CustomAccordionItem)itemsHost.Children[nitem];
// tooltip for facet category header
stringtooltip;
string facetName = ((FacetCategory)item.Content).Name;
switch(facetName){
case “AppCount”:tooltip = “Count of applications in the Marketplace”;
break;
case “Ranking”:tooltip = “Overall ranking in the Marketplace”;
break;
…
ToolTipService.SetToolTip(item, “Facet:\n”+ tooltip);
If you take a look at this set of pivot collections,
visualizing the WP7 Marketplace, you will see facet tooltips are implemented:
WP7 APP HUB
FAQ
If you want to try out the code there are a few things to watch out for. You will not be able to set the tooltips before the collection event CollectionLoadingCompleted has completed and exited. If you wrap your tooltip code in a function then you can call it from this event using the control’s dispatcher:
this.Dispatcher.BeginInvoke(SetToolTips);
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
Conclusion
This article is just a brief tutorial that includes the key features of using the tooltip service control in code to attach custom tooltips to visual elements of the Silverlight PivotViewer control. It targets the developer who has already started customizing the Silverlight PivotViewer control beyond the public API. Any comments or request for future topics are welcome.