How to hide PivotItem header?

I want to have a Pivot element that has PivotItems, but there is no Header text title element in the landscape (this is a gallery in landscape mode, when returning to the portrait it should display the PivotItems header again).

The decision to make the text PivotItem.Header = "" inconvenient, since the space occupied by the header text is still reserved (so there is an empty space that is not used).

How can i do this?

+6
source share
3 answers

You can set the top Margin your summary items to a negative value to move them:

 <controls:PivotItem Header="item1" Margin="0,-100,0,0"> 

It does not delete the title, but your gallery elements will be on top of it and therefore have more free space. Combine this with the idea of โ€‹โ€‹cleaning signatures, and you may have a solution.

+6
source

A more elegant solution: just override the HeaderTemplate header with the invisible (but not compensated) DataTemplate:

 <controls:Pivot.HeaderTemplate> <DataTemplate> <StackPanel Height="0" Width="0"> <TextBlock Text="{Binding}" /> </StackPanel> </DataTemplate> </controls:Pivot.HeaderTemplate> 
+3
source

You can first save the headers of all pivotitems, and then set all the pivotitems headers to an empty line, after which all areas of the rotary section disappear. You can restore them using the saved header information.

  private void ResotorePivotItemHeaders() { if (_pivotItemHeaders.Count == pivot.Items.Count) { for (int i = 0; i < _pivotItemHeaders.Count; i++) (pivot.Items[i] as PivotItem).Header = _pivotItemHeaders[i]; } } private void HidePivotItemHeaders() { if (pivot.Items.Count == 0) return; _pivotItemHeaders.Clear(); for (int i = 0; i<pivot.Items.Count; i++) { PivotItem item = pivot.Items[i] as PivotItem; _pivotItemHeaders.Add(item.Header as String); item.Header = ""; } } List<String> _pivotItemHeaders = new List<string>(); 
0
source

Source: https://habr.com/ru/post/900771/


All Articles