Alex
Alex

Reputation: 11137

How to hide PivotItem Header?

I wish to have a Pivot control that has PivotItems but no pivot item Header text in landscape (it's a gallery in landscape mode, when reverted to portrait it should display the PivotItems header again).

The solution to make the text PivotItem.Header = "" is not good since the space occupied by the header text is still reserved (so there's a blank space that is not used).

How can I do so?

Upvotes: 7

Views: 5080

Answers (3)

Chunde  Huang
Chunde Huang

Reputation: 385

You can first save headers of all pivotitem, then set all the pivotitems' header to empty string, after that, all the pivothead region will 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>();

Upvotes: 0

maxdelia
maxdelia

Reputation: 868

A more elegant solution: just override the deafult HeaderTemplate with a non-visibile (but NOT collapsed) DataTemplate:

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

Upvotes: 3

Heinrich Ulbricht
Heinrich Ulbricht

Reputation: 10372

You can set the top Margin of your pivot items to a negative value to move them up:

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

It doesn't remove the header, but your gallery items will be on top of it and thus have more space available. Combine this with your idea of clearing the captions and you could have a solution.

Upvotes: 7

Related Questions