Creating Pivot Footers on Windows phone 7 application

柔情痞子 提交于 2019-12-01 12:57:14

You can create your own style for Pivot control. The easiest way to move header down is create a copy of default Pivot style and slightly modify it.

    <Style x:Key="PivotStyle" TargetType="controls:Pivot">
        <Setter Property="Margin" Value="0"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <Grid/>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:Pivot">
                    <Grid HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Grid Background="{TemplateBinding Background}" CacheMode="BitmapCache" Grid.RowSpan="3"/>
                        <ContentPresenter ContentTemplate="{TemplateBinding TitleTemplate}" Content="{TemplateBinding Title}" Margin="24,17,0,-7"/>
                        <ItemsPresenter x:Name="PivotItemPresenter" Margin="{TemplateBinding Padding}" Grid.Row="1"/>
                        <controlsPrimitives:PivotHeadersControl x:Name="HeadersListElement" Grid.Row="2"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

<controls:Pivot Title="pivot" Style="{StaticResource PivotStyle}">

I have the solution. You need to inherit from Pivot control and switch headers row with items row:

  public class PivotFooter : Pivot
  {
    public override void OnApplyTemplate()
    {
      base.OnApplyTemplate();

      var headers = base.GetTemplateChild("HeadersListElement") as PivotHeadersControl;
      var items = base.GetTemplateChild("PivotItemPresenter") as ItemsPresenter;

      var grid = headers.Parent as Grid;
      if(grid != null)
      {
        var firstHeight = grid.RowDefinitions[1].Height;
        var secondHeight = grid.RowDefinitions[2].Height;

        grid.RowDefinitions[1].Height = secondHeight;
        grid.RowDefinitions[2].Height = firstHeight;    
      }

      headers.SetValue(Grid.RowProperty, 2);
      items.SetValue(Grid.RowProperty, 1);
    }
  }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!