2013-10-02 31 views
5

我的透视控件的样式有一个奇怪的问题。 我在Expression Blend中编辑了一个默认模板的副本,因为我想删除整个标题。Windows Phone 8:删除数据透视表标头

的改编风格:

<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)'访问冲突'”出现。

我看了一些帖子,这样的头是在屏幕的向上移动枢轴,但我需要我的个性支点在我的网页与它上面的一些其他控件的底部。

有没有人有一个想法如何删除标题?

编辑:为了清楚我想删除标题和标题。

+1

你找出如何做到这一点? – halileohalilei

+0

某种。请看标记的答案。 – Danscho

回答

2

Pivot控件的模板在WP8被改变,而现在要求PivotHeadersControl存在于模板。 (您可以在WP7.x中将其删除)
只需在头文件中标记零高度或其他“空”内容。

我没有意识到这一点已被公开记录为谁已经升级到WP8正在使用的垫片,以旧版本的控制的大多数人。但是,我在http://blog.mrlacey.co.uk/2013/01/pivot-and-panorama-have-moved-and.html

+0

感谢马特的链接。我想删除标题和标题。对此有何建议?我已经尝试设置不透明度和高度(标题仍然存在,但与pivotitem的内容重叠)。 – Danscho

8

的博客文章结尾处注意到此问题您可以通过用空白DataTemplate替换Pivot.HeaderTemplate属性来删除Pivot控件上的PivotItem标题。如果您试图删除标题而不是标题,那么我也想知道该解决方案。 ^^

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

是的,我想删除标题和标题。对不起,我的问题不清楚。 – Danscho

+0

用空的DataTemplate替换HeaderTemplate应删除标题和标题 – PompolutZ

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

...

+0

这完美适用于Windows Phone 8.1解决方案。我相信用Header的一个空白数据模板,这也可以用于通用应用程序。谢谢! –

0

我终于想通出来! (我正在构建一个通用Windows 10应用程序并且有同样的问题。)

添加一个空白HeaderTemplate中您枢轴控件dBlisse建议:

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

并添加此模板的App.xaml:

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