Open JPfahl opened 3 days ago
In some cases you can use similiar code like this as a workaround (the example is part of a bug fixed by Syncfusion recently). There might be problems with spaces in names.
builder
.UseMauiApp<App>()
// Initialize the .NET MAUI Community Toolkit by adding the below line of code
.UseMauiCommunityToolkit()
.UseBarcodeReader()
.ConfigureFonts(fonts =>
{
// :Information: It seems that the Alias should be some unique value otherwise it seemingly causes malfunction in iOS
// (not displaying inherited StyleClass correctly). Strange but... whatever.
fonts.AddFont("Lobster-Regular.ttf", "lobster_unique_name");
fonts.AddFont("ionicons.ttf", "ionicons_unique_name");
fonts.AddFont("Maui Material Assets.ttf", "Maui Material Assets");
}).ConfigureMauiHandlers((handlers) =>
{
#if IOS
handlers.AddHandler(typeof(Shell), typeof(CustomShellRenderer));
handlers.AddHandler(typeof(Editor), typeof(CustomEditorHandler));
#endif
});
#if WINDOWS
// :Information: Workaround
// in WinUI context MAUI uses the ms-appx URI scheme to locate embedded source files (like fonts)
// In this case this is needed to resolve Syncfusion's "Maui Material Assets.ttf" (which contains
// icons for example for SfExpander)
// Source: https://github.com/dotnet/maui/issues/9104
Microsoft.Maui.Handlers.LabelHandler.Mapper.AppendToMapping("FontFamily", (handler, element) =>
{
if (element.Font.Family == "Maui Material Assets")
{
const string font = "ms-appx:///Maui Material Assets.ttf#Maui Material Assets";
handler.PlatformView.FontFamily = new Microsoft.UI.Xaml.Media.FontFamily(font);
}
});
/* does not work
Microsoft.Maui.Handlers.ButtonHandler.Mapper.AppendToMapping("FontFamily", (handler, element) =>
{
if ((element as Button).FontFamily == "Maui Material Assets")
{
const string font = "ms-appx:///Maui Material Assets.ttf#Maui Material Assets";
handler.PlatformView.FontFamily = new Microsoft.UI.Xaml.Media.FontFamily(font);
}
});
*/
#endif
Hi @JPfahl. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md
This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
Description
When I run the app on windows with packaging turned off the font resources in the app are not loaded. If I package the app it works as expected. All of the font files are set to copy always.
Unpackaged
Packaged
Steps to Reproduce
No response
Link to public reproduction project repository
No response
Version with bug
9.0.10 SR1
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
No response
Affected platforms
Windows
Affected platform versions
No response
Did you find any workaround?
Package the app
Relevant log output