2014-04-11 66 views
5

我期待能够修改默认数据透视模板以更改数据透视项标题的大小。我怎么可以这样做有以下样式如何更改模板中枢轴项目标题的大小

<Style x:Key="PivotStyle" 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 CacheMode="BitmapCache" Grid.RowSpan="2" > 
          <Grid.Background> 
           <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> 
            <GradientStop Color="Transparent" Offset="0.0" /> 
            <GradientStop Color="Transparent" Offset="1.0" /> 
           </LinearGradientBrush> 
          </Grid.Background> 
         </Grid> 
         <Grid Background="{TemplateBinding Background}" CacheMode="BitmapCache" Grid.Row="2" /> 
         <ContentPresenter ContentTemplate="{TemplateBinding TitleTemplate}" Content="{TemplateBinding Title}" Margin="24,17,0,-7" /> 
         <Primitives:PivotHeadersControl x:Name="HeadersListElement" Foreground="{StaticResource PhoneForegroundBrush}" FontSize="28" Grid.Row="1"/> 
         <ItemsPresenter x:Name="PivotItemPresenter" Margin="{TemplateBinding Padding}" Grid.Row="2"/> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

我试图得到这个模拟天生以下

enter image description here

+0

你是什么意思改变标题大小? ''? – Romasz

+0

更新字体大小没有效果。更改为FontSize =“18”进行测试。 – Matthew

回答

10

你一定能够改变你的数据透视表头的字体大小,家庭等通过改变HeaderTemplate中:

<phone:Pivot Title="PivotTest" Style="{StaticResource PivotStyle}"> 
    <phone:Pivot.HeaderTemplate> 
     <DataTemplate> 
      <TextBlock Text="{Binding}" FontSize="10"/> 
     </DataTemplate> 
    </phone:Pivot.HeaderTemplate> 
    <phone:PivotItem Header="One"> 
      // item 1 
    </phone:PivotItem> 
    <phone:PivotItem Header="Two"> 
      // item 2 
    </phone:PivotItem> 
</phone:Pivot> 

编辑 - 风格中:

<phone:PhoneApplicationPage.Resources> 
    <DataTemplate x:Key="myHeader"> 
     <TextBlock Text="{Binding}" FontSize="10"/> 
    </DataTemplate> 

    <Style x:Key="PivotStyle" TargetType="phone:Pivot"> 
     <Setter Property="HeaderTemplate" Value="{StaticResource myHeader}"/> 
     <Setter Property="Margin" Value="0"/> 
     .... 
+0

谢谢,我会放弃这一点。然而,我的最终目标是创建一种风格,这样我就可以将它应用到我的应用程序中的所有透视项目,然后在必要时更改样式。 – Matthew

+0

@Matthew这不是问题(请参阅编辑) - 您可以定义DataTemplate并使用透视样式中的setter进行设置。 – Romasz