【发布时间】:2021-06-07 07:24:56
【问题描述】:
有什么方法可以更改 Xamarin Forms Shell 中 FlyoutItem 内的字体系列内容吗?
我已经在共享项目中添加了自定义 .ttf 字体作为嵌入资源,并且还使用文件 AssemblyInfo.cs 向程序集注册了字体文件。
任何帮助将不胜感激。
【问题讨论】:
标签: xaml xamarin.forms embedded-fonts xamarin.forms.shell
有什么方法可以更改 Xamarin Forms Shell 中 FlyoutItem 内的字体系列内容吗?
我已经在共享项目中添加了自定义 .ttf 字体作为嵌入资源,并且还使用文件 AssemblyInfo.cs 向程序集注册了字体文件。
任何帮助将不胜感激。
【问题讨论】:
标签: xaml xamarin.forms embedded-fonts xamarin.forms.shell
对于Shell 弹出内容(弹出项+菜单项),您可以使用FlyoutItemLabelStyle 类的样式:
<Style ApplyToDerivedTypes="True" Class="FlyoutItemLabelStyle" TargetType="Label">
<Setter Property="FontFamily" Value="YourFontExportName"/>
</Style>
来自文档Style FlyoutItem and MenuItem objects。
How to use Font Awesome icons in project as an icon of ImageButton
Using Material Design Icons with Xamarin Forms - What Am I Missing?
【讨论】:
就像 Cfun 说的,您可以使用 FlyoutItemLabelStyle 设置 Shell Flyout 项目字体。
将字体作为嵌入式资源 (Build Action: EmbeddedResource) 添加到 Xamarin.Forms 共享项目。
使用ExportFont 属性在AssemblyInfo.cs 等文件中向程序集注册字体文件。也可以指定一个可选的别名。
AssemblyInfo.cs:
[assembly: ExportFont("Trashtalk.ttf", Alias = "Trashtalk")]
以您的风格添加此字体。
<Style Class="FlyoutItemLabelStyle" TargetType="Label">
<Setter Property="FontFamily" Value="Trashtalk" />
</Style>
截图:
【讨论】: