在构建 .Maui 应用程序时,我们已经让 Windows 版本可以运行。然而,与 Android 和 IOS 版本不同,Windows 版本不会加载任何我们的 Fontawesome 图标。
它们不像我看到其他人得到的那样是空白方块,它们只是完全空白。
MauiProgram.cs 有这一行:
fonts.AddFont("font-awesome-solid.otf", "font-awesome-solid");
图标不起作用的一个例子是这一行:
<customcontrols:CustomButton
Grid.Column="1"
Grid.Row="2"
x:Name="NextButton"
Text="{x:Static resources:AppResources.buttonTextNextPage}"
Clicked="OnNextButtonClicked">
<Button.ImageSource>
<FontImageSource FontFamily="font-awesome-solid"
Glyph="{x:Static fonts:FontAwesome.CaretRight}"
Size="32" />
</Button.ImageSource>
</customcontrols:CustomButton>
我尝试过搜索,但现在完全被难住了,任何想法将不胜感激!
编辑:我想我最好给出 CustomButton 内部的内容,因为我觉得问题可能存在
public CustomButton() {
this.SetDynamicResource(VisualElement.StyleProperty, SystemConstant.CustomButtonStyle);
}
private string _glyphName = null;
public string Glyph {
get
{
return _glyphName;
}
set
{
_glyphName = value;
var fis = new FontImageSource
{
FontFamily = "font-awesome-solid#",
Glyph = value,
Size = 25,
};
fis.SetDynamicResource(FontImageSource.ColorProperty, "LabelTextColor");
this.ImageSource = fis;
}
}
有点虎头蛇尾的答案,但似乎我们所做的只是更新了 dotnet 以及我们的一些库。 因此,尽管从未弄清楚问题是什么,但更新已经解决了问题,并且图标现在在 Windows 中可见