如何在Xamarin UWP中更改导航栏中标题的字体大小

时间:2017-05-15 08:56:12

标签: uwp xamarin.forms

我想在Xamarin UWP中更改导航栏中标题的字体大小。还想在导航栏的中心获取标题。我怎样才能实现它。我无法找到解决方案。有没有人实现过它。

1 个答案:

答案 0 :(得分:1)

Before customizing the page title font size please refer to the Xamarin.Forms PageControlStyle

<uwp:FormsCommandBar.Content>
    <Border x:Name="TitleArea" Visibility="{TemplateBinding TitleVisibility}" Height="{ThemeResource TitleBarHeight}">
        <TextBlock Text="{Binding Title}" TextWrapping="NoWrap" VerticalAlignment="Center" Margin="10,0,0,0" Foreground="{TemplateBinding TitleBrush}" Style="{ThemeResource TitleTextBlockStyle}" />
    </Border>
</uwp:FormsCommandBar.Content>

As you can see, the title of ContentPage was rendered by TextBlock within uwp platform, and the style of TextBlock was TitleTextBlockStyle. So you could change the tile font size by modifying the TitleTextBlockStyle within uwp client project.

<Application.Resources>
     <ResourceDictionary>
         <Style
             x:Key="TitleTextBlockStyle"
             BasedOn="{StaticResource BaseTextBlockStyle}"
             TargetType="TextBlock">
             <Setter Property="FontWeight" Value="SemiLight" />
             <Setter Property="FontSize" Value="18" />
             <Setter Property="OpticalMarginAlignment" Value="TrimSideBearings" />
         </Style>
     </ResourceDictionary>
 </Application.Resources>

But it does not recommend that change the layout of title. Because the internal FormsPresenter could not be modified in uwp client project when you custom PageControl style!