问题描述
有什么方法可以更改 Xamarin Forms FlyoutItem
中 Shell
中内容的字体系列吗?
我已经在共享项目中添加了自定义 .ttf
字体作为嵌入资源,并且还使用文件 AssemblyInfo.cs
向程序集注册了字体文件。
任何帮助将不胜感激。
解决方法
对于 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>
截图: