Windows Phone 8:删除数据透视表头

时间:2013-10-02 14:11:59

标签: windows-phone-8 pivotitem

我的枢轴控制的造型有一个奇怪的问题。 我在Expression Blend中编辑了默认模板的副本,因为我想删除整个标题。

改编的风格:

<Style x:Key="PivotWithoutHeader" TargetType="phone: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="phone:Pivot">
                    <Grid HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <Grid Background="{TemplateBinding Background}" Grid.RowSpan="3"/>
                        <!--<ContentControl ContentTemplate="{TemplateBinding TitleTemplate}" Content="{TemplateBinding Title}" HorizontalAlignment="Left" Margin="24,17,0,-7" Style="{StaticResource PivotTitleStyle}"/>-->
                        <Primitives:PivotHeadersControl x:Name="HeadersListElement" Grid.Row="1"/>
                        <ItemsPresenter x:Name="PivotItemPresenter" Margin="{TemplateBinding Padding}" Grid.Row="2"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

我的风格用法:

<phone:Pivot Grid.Row="1" x:Name="Objects" ItemsSource="{Binding Profiles}" 
                                 Style="{StaticResource PivotWithoutHeader}">
                        <phone:Pivot.ItemContainerStyle>
                            <Style TargetType="phone:PivotItem">
                                <Setter Property="HorizontalAlignment" Value="Stretch" />
                            </Style>
                        </phone:Pivot.ItemContainerStyle>
                        <phone:Pivot.ItemTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Image Source="Resources/homer.png"/>
                                    <TextBlock Text="{Binding Name}"/>
                                    <TextBlock Text="#Sample" />
                                    <Button Margin="347,0,0,0" Command="{Binding DataContext.SettingsCommand, ElementName=Objects}" CommandParameter="{Binding .}" />
                                </Grid>
                            </DataTemplate>
                        </phone:Pivot.ItemTemplate>
                    </phone:Pivot>

我的想法只是删除或设置<Primitives:PivotHeadersControl>折叠后的可见性,但我的应用程序崩溃没有任何异常,并在输出窗口中显示以下消息:“程序'[2332] TaskHost.exe'具有退出代码-1073741819(0xc0000005)出现“访问冲突”。

我阅读了一些帖子以向上移动枢轴,以便标题位于屏幕之外但我需要在页面底部使用我自定义的枢轴,并在其上方设置其他控件。

有人知道如何删除标题吗?

编辑:为清楚起见,我想删除标题和标题。

6 个答案:

答案 0 :(得分:8)

您可以通过使用空白DataTemplate替换Pivot.HeaderTemplate属性来删除数据透视表控件上的PivotItem标头。如果你想删除Title而不是Header,那么我也想知道解决方案。 ^^

<phone:Pivot ItemsSource="{Binding Data}" ItemTemplate="{StaticResource CustomPivotItemTemplate}">
    <phone:Pivot.HeaderTemplate>
        <DataTemplate/>
    </phone:Pivot.HeaderTemplate>
</phone:Pivot>

答案 1 :(得分:3)

试试这个:

<UserControl.Resources>
    <ResourceDictionary>
        <Thickness x:Key="PivotPortraitThemePadding">0,0,0,0</Thickness>
        <Thickness x:Key="PivotLandscapeThemePadding">0,0,0,0</Thickness>
        <Style x:Key="PivotWithoutHeaderStyle" TargetType="Pivot">
            <Setter Property="Margin" Value="0"/>
            <Setter Property="Padding" Value="0"/>
            <Setter Property="Foreground" Value="{ThemeResource PhoneForegroundBrush}"/>
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <Grid/>
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Pivot">
                        <Grid x:Name="RootElement" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="Orientation">
                                    <VisualState x:Name="Portrait">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="TitleContentControl">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Landscape">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="TitleContentControl">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <ContentControl x:Name="TitleContentControl" ContentTemplate="{TemplateBinding TitleTemplate}" Content="{TemplateBinding Title}" Style="{StaticResource PivotTitleContentControlStyle}" Height="0"/>
                            <ScrollViewer x:Name="ScrollViewer" HorizontalSnapPointsAlignment="Center" HorizontalSnapPointsType="MandatorySingle" HorizontalScrollBarVisibility="Hidden" Margin="0" Grid.Row="1" Template="{StaticResource ScrollViewerScrollBarlessTemplate}" VerticalSnapPointsType="None" VerticalScrollBarVisibility="Disabled" VerticalScrollMode="Disabled" VerticalContentAlignment="Stretch" ZoomMode="Disabled">
                                <PivotPanel x:Name="Panel" VerticalAlignment="Stretch">
                                    <PivotHeaderPanel x:Name="Header" Background="{TemplateBinding BorderBrush}" Height="0" Margin="0" Visibility="Collapsed">
                                        <PivotHeaderPanel.RenderTransform>
                                            <CompositeTransform x:Name="HeaderTranslateTransform" TranslateX="0"/>
                                        </PivotHeaderPanel.RenderTransform>
                                    </PivotHeaderPanel>
                                    <ItemsPresenter x:Name="PivotItemPresenter">
                                        <ItemsPresenter.RenderTransform>
                                            <TranslateTransform x:Name="ItemsPresenterTranslateTransform" X="0"/>
                                        </ItemsPresenter.RenderTransform>
                                    </ItemsPresenter>
                                </PivotPanel>
                            </ScrollViewer>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </ResourceDictionary>
</UserControl.Resources>

...

    <Pivot Style="{StaticResource PivotWithoutHeaderStyle}">

...

答案 2 :(得分:2)

在WP8中更改了Pivot控件的模板,现在要求模板中存在PivotHeadersControl。 (你可以在WP7.x中删除它)
只需在标题中包含零高度或其他“空”内容。

我不知道这已被公开记录,因为大多数升级到WP8的人都使用垫片来控制旧版本。但是,我在http://blog.mrlacey.co.uk/2013/01/pivot-and-panorama-have-moved-and.html

的博客文章末尾注意到了这一点

答案 3 :(得分:1)

因此删除标题和标题在Windows Phone 8上不再起作用。 因此,我将现有控件从http://www.codeproject.com/Articles/136786/Creating-an-Animated-ContentControl移植到Windows Phone 8。

答案 4 :(得分:0)

dBlisse的解决方案让我隐藏了标题模板,但是对于标题我玩边距并且下面的技巧对我有效,不确定这是不是一个好主意,但检查了不同的分辨率,看起来很好。

请注意下面的堆栈面板的Margin="0,-39,0,0"

<phone:Pivot Background="Transparent" Margin="-12,0">
    <phone:Pivot.ItemTemplate>
        <DataTemplate>
             <StackPanel Margin="0,-39,0,0">
                  YOUR CONTROLS HERE
             </StackPanel>
        </DataTemplate>
    </phone:Pivot.ItemTemplate>
    <phone:Pivot.HeaderTemplate>
        <DataTemplate/>
    </phone:Pivot.HeaderTemplate>
</phone:Pivot>

答案 5 :(得分:0)

我终于明白了! (我正在构建一个通用Windows 10应用程序并遇到同样的问题。)

将空白HeaderTemplate添加到您的Pivot控件,如dBlisse建议:

<Pivot ItemsPanel="{StaticResource ItemsPanelTemplate1}">
    <Pivot.HeaderTemplate>
        <DataTemplate/>
    </Pivot.HeaderTemplate>
</Pivot>

在App.xaml中添加此模板:

<ItemsPanelTemplate x:Key="ItemsPanelTemplate1">
    <Grid Margin="0,-48,0,0"/>
</ItemsPanelTemplate>