PivotItem Header won't change to a custom font

2019-08-31 09:18发布

问题:

PivotItem Header font will not change. Property is set to Content. This font works in other areas of my app, but not the PivotItem Header.

<controls:Pivot Margin="0">
    <controls:PivotItem Header="Welcome" FontFamily=".Fonts/sketch123.ttf#sketch123">
</controls:PivotItem>

回答1:

Tried this before but it didnt work. I must've typed it wrong initially. This works:

<controls:PivotItem >
            <controls:PivotItem.Header>
                <TextBlock Text="welCome" FontFamily="Heart Breaking Bad" FontSize="80" Margin="24,20,20,0"/>
            </controls:PivotItem.Header>


回答2:

Add to ResourceDictionary (without primitives:) and edit as you like (for windows phone 8.1 store)

 <x:Double x:Key="PivotHeaderItemFontSize">57</x:Double>
    <x:Int32 x:Key="PivotHeaderItemCharacterSpacing">-25</x:Int32>
    <FontFamily x:Key="PivotHeaderItemFontFamily">Segoe WP SemiLight</FontFamily>
    <Thickness x:Key="PivotHeaderItemPadding">0,0,0,6.5</Thickness>
    <Thickness x:Key="PivotHeaderItemMargin">16,-6.5,0,0</Thickness>


<Style TargetType="primitives:PivotHeaderItem">
            <Setter Property="FontSize" Value="{ThemeResource PivotHeaderItemFontSize}" />
            <Setter Property="FontFamily" Value="{ThemeResource PivotHeaderItemFontFamily}" />
            <Setter Property="CharacterSpacing" Value="{ThemeResource PivotHeaderItemCharacterSpacing}" />
            <Setter Property="Background" Value="{ThemeResource PivotHeaderBackgroundUnselectedBrush}" />
            <Setter Property="Foreground" Value="{ThemeResource PivotHeaderForegroundUnselectedBrush}" />
            <Setter Property="Margin" Value="{ThemeResource PivotHeaderItemMargin}" />
            <Setter Property="Padding" Value="{ThemeResource PivotHeaderItemPadding}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="primitives:PivotHeaderItem">
                        <Grid x:Name="Grid">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="SelectionStates">
                                    <VisualStateGroup.Transitions>
                                        <VisualTransition From="Unselected"
                                                          GeneratedDuration="0:0:0.33"
                                                          To="UnselectedLocked" />
                                        <VisualTransition From="UnselectedLocked"
                                                          GeneratedDuration="0:0:0.33"
                                                          To="Unselected" />
                                    </VisualStateGroup.Transitions>
                                    <VisualState x:Name="Unselected" />
                                    <VisualState x:Name="UnselectedLocked">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0"
                                                             Storyboard.TargetName="ContentPresenterTranslateTransform"
                                                             Storyboard.TargetProperty="X"
                                                             To="{ThemeResource PhonePivotLockedTranslation}" />
                                            <DoubleAnimation Duration="0"
                                                             Storyboard.TargetName="ContentPresenter"
                                                             Storyboard.TargetProperty="(UIElement.Opacity)"
                                                             To="0" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Selected">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource PivotHeaderForegroundSelectedBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Grid" Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource PivotHeaderBackgroundSelectedBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <ContentPresenter x:Name="ContentPresenter"
                                              Margin="{TemplateBinding Padding}"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              Content="{TemplateBinding Content}"
                                              ContentTemplate="{TemplateBinding ContentTemplate}">
                                <ContentPresenter.RenderTransform>
                                    <TranslateTransform x:Name="ContentPresenterTranslateTransform" />
                                </ContentPresenter.RenderTransform>
                            </ContentPresenter>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

for Sirverlite