2013-10-02 30 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>