如何在Xamarin UWP中更改CommandBar Title字体大小

时间:2016-10-03 11:36:29

标签: xamarin.forms uwp xamarin.uwp

我创建了一个Xamarin.Forms应用程序,有很长的名字。 当我在我的4.5" Windows 10手机,看起来很奇怪。

主页面由TabbedPage组成,并且具有Title属性,但它没有FontSize属性。

enter image description here

我在PCL项目中使用以下Style

 <Style TargetType="Label">     
        <Setter Property="TextColor" Value="{StaticResource BaseColor}" />
        <Setter Property="FontSize">
            <Setter.Value>
                <OnIdiom x:TypeArguments="x:Double"
                         Phone="18"
                         Tablet="28" />
            </Setter.Value>
        </Setter>
    </Style>

但是,如果删除它,标题仍然非常大。

在哪里可以修改标题字体大小以使标题更小

更新

我使用动态属性编辑器进行了检查,结果显示Title位于CommandBar内,FontSize设置为24。

enter image description here

我试图覆盖它的样式(在XAML和代码中),但它不起作用:

 <forms:WindowsPage.BottomAppBar>
        <CommandBar>
            <CommandBar.Style>
                <Style TargetType="CommandBar">
                    <Setter Property="FontSize" Value="4" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <TextBlock Text="Whatever" />
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </CommandBar.Style>
            <CommandBar.Content>
                <TextBlock Text="Whatever" />
            </CommandBar.Content>
        </CommandBar>
    </forms:WindowsPage.BottomAppBar>



 public MainPage()
 {
  this.InitializeComponent();
  var bapp = BottomAppBar;
  LoadApplication(new MyXamarinApp.App(IoC.Get<SimpleContainer>()));
  BottomAppBar = bapp;
  BottomAppBar.FontSize = 4;
 }

有什么想法吗?

更新2:

您可以从here下载示例项目。

1 个答案:

答案 0 :(得分:0)

您必须 覆盖其中一种内置样式:

 <!-- Tab title  -->
 <Style x:Key="TitleTextBlockStyle" TargetType="TextBlock">
    <Setter Property="FontSize" Value="18" />
    <Setter Property="TextWrapping" Value="NoWrap" />
    <Setter Property="TextTrimming" Value="CharacterEllipsis" />
 </Style>