Creating Pivot Footers on Windows phone 7 application

后端 未结 2 546
旧时难觅i
旧时难觅i 2021-01-16 14:19

I know that pivot control of windows phone has two parts pivot headers and pivot item control.

what i want to display is, pivot headers below the pivot item control

相关标签:
2条回答
  • 2021-01-16 14:37

    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}">

    0 讨论(0)
  • 2021-01-16 14:47

    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);
        }
      }
    
    0 讨论(0)
提交回复
热议问题