0

FlyoutItem有什么方法可以更改Xamarin Forms中内容的字体系列Shell吗?

我已经.ttf在共享项目中添加了自定义字体作为嵌入式资源,并且还使用文件AssemblyInfo.cs.

任何帮助,将不胜感激。

4

2 回答 2

2

对于Shell弹出内容(弹出项 + 菜单项),您可以使用带有FlyoutItemLabelStyle类的样式:

<Style ApplyToDerivedTypes="True" Class="FlyoutItemLabelStyle" TargetType="Label">
     <Setter Property="FontFamily" Value="YourFontExportName"/>
</Style>

来自文档样式 FlyoutItem 和 MenuItem 对象

相关问题

如何在项目中使用 Font Awesome 图标作为 ImageButton 的图标

将 Material Design 图标与 Xamarin 表单一起使用 - 我错过了什么?

于 2021-03-09T12:33:24.953 回答
0

就像 Cfun 说的那样,您可以将 Shell Flyout 项目字体设置为FlyoutItemLabelStyle.

  1. 将字体作为嵌入资源 ( Build Action: EmbeddedResource) 添加到 Xamarin.Forms 共享项目。

  2. 使用 ExportFont 属性在 AssemblyInfo.cs 等文件中向程序集注册字体文件。也可以指定一个可选的别名。

    AssemblyInfo.cs

    [assembly: ExportFont("Trashtalk.ttf", Alias = "Trashtalk")]
    
  3. 以您的风格添加此字体。

    <Style Class="FlyoutItemLabelStyle" TargetType="Label">
             <Setter Property="FontFamily" Value="Trashtalk" />
         </Style>
    

截屏:

在此处输入图像描述

于 2021-03-10T06:13:00.567 回答