Note that there are some explanatory texts on larger screens.

plurals
  1. POChange Pivot's HeaderTemplate after initialization
    text
    copied!<p>I'm trying to change the HeaderTemplate of a Pivot when the PhoneApplicationPage Orientation changes to accomodate a different screen real-estate. The end-effect I'm trying to achieve is to shrink the Pivot Header FontSize in Landscape to make room for more vertical content.</p> <p>The templates are declared in XAML as Resources;</p> <pre><code>&lt;phone:PhoneApplicationPage.Resources&gt; &lt;DataTemplate x:Key="landscapePivotTitleTemplate"&gt; &lt;TextBlock Text="" Height="0"/&gt; &lt;/DataTemplate&gt; &lt;DataTemplate x:Key="portraitPivotTitleTemplate"&gt; &lt;TextBlock Text="{Binding}" /&gt; &lt;/DataTemplate&gt; &lt;DataTemplate x:Key="portraitPivotHeaderTemplate"&gt; &lt;TextBlock Text="{Binding}" /&gt; &lt;/DataTemplate&gt; &lt;DataTemplate x:Key="landscapePivotHeaderTemplate"&gt; &lt;TextBlock Text="{Binding}" FontSize="{StaticResource PhoneFontSizeSmall}" /&gt; &lt;/DataTemplate&gt; &lt;/phone:PhoneApplicationPage.Resources&gt; </code></pre> <p>I assign the DataTemplate from the Page's FrameworkElement.Resource ResourceDictionary in a handler for OrientationChanged;</p> <pre><code>void MainPage_OrientationChanged(object sender, OrientationChangedEventArgs e) { if (e.Orientation == PageOrientation.LandscapeLeft || e.Orientation == PageOrientation.LandscapeRight) { pivot.HeaderTemplate = (DataTemplate)Resources["landscapePivotHeaderTemplate"]; pivot.TitleTemplate = (DataTemplate)Resources["landscapePivotTitleTemplate"]; } else { pivot.HeaderTemplate = (DataTemplate)Resources["portraitPivotHeaderTemplate"]; pivot.TitleTemplate = (DataTemplate)Resources["portraitPivotTitleTemplate"]; } } </code></pre> <p>Using the above templates, the Title is correctly hidden by assigning to the TitleTemplate. However, it appears that it's only possible to set the Header template once - and subsequent assignments to the HeaderTemplate is only made effective by adding new PivotItem's. Is there a better way to approach this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload