WP7 Pivot’s TitleTemplate contains Title & Subtitle

I tried to add to Textblocks to the Pivot':TitleTemplate and got an error "The property 'VisualTree' is set more than once." In order to work around this, I had to add a containing object (Stackpanel) that could contain both objects.

In order to do that, create a TitleTemplate that contains a StackPanel with your Title and Subtitle Textblocks inside. The image below shows the Title and Subtitle above the pivot header.


The XAML to produce this is below:
   1:              <controls:Pivot.TitleTemplate>
   2:                  <DataTemplate>
   3:                      <StackPanel>
   4:                      <TextBlock x:Name="TextBlockPivotDeploymentItemHeading"
   5:                          Text="Title"
   6:                          FontSize="20"
   7:                          TextWrapping="Wrap"/>
   8:                      <TextBlock x:Name="subtitle"
   9:                          Text="Subtitle"
  10:                          Foreground="Gray"
  11:                          TextWrapping="Wrap"/> 
  12:                          </StackPanel>                               
  13:                  </DataTemplate>
  14:              </controls:Pivot.TitleTemplate>


Popular posts from this blog

Yet once more into the breech (of altered programming logic)

Simple WP7 Mango App for Background Tasks, Toast, and Tiles: Code Explanation

How to convert SVG data to a Png Image file Using InkScape