如何更改模板中数据透视表项目标题的大小

时间:2014-04-11 23:17:29

标签: xaml windows-phone-8

我希望能够修改默认的数据透视表模板来更改数据透视表项标题的大小。我如何使用以下样式

执行此操作
<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

1 个答案:

答案 0 :(得分:11)

您可以通过更改HeaderTemplate来确定更改您的Pivot Header的字体大小,系列等:

<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"/>
        ....