radimitrov / CSharpShellApp

77 stars 18 forks source link

Resource not found #337

Open PeterKaa1 opened 7 months ago

PeterKaa1 commented 7 months ago

Resource "Resources/Fonts/LilitaOne-Regular.ttf" not found.

Why?? The path is correct.

equin0X35 commented 7 months ago

i assume that we apply new font to a Label. First, in mauiprogram register your font to the app builder by the builder's ConfigureFont extension method:

var builder = MauiApp.CreateBuilder();
    builder.UseMauiApp<App>()
    .UseMauiCommunityToolkit()
    .ConfigureFonts(fonts =>{
        .fonts.AddFont("Resources/Fonts/Aquire-Bold.otf", "Aquire");
    });

the app will automatically search the font in the local project directory, you can then consume it like so:<Label Text="Aquire in Bold" FontFamily="Aquire"/>. This works on me you could try it huhu😅

equin0X35 commented 7 months ago

but after doing so try exporing it as apk.

radimitrov commented 7 months ago

To clarify, fonts work in an independent APK but not inside C# Shell? Is replacing

fonts.AddFont("Resources/Fonts/Aquire-Bold.otf", "Aquire");

with

fonts.AddEmbeddedResourceFont(System.Reflection.Assembly.GetExecutingAssembly(), "Resources/Fonts/Aquire-Bold.otf", "Aquire");

a workaround here?

Edit: Also try changing "Resources/Fonts/Aquire-Bold.otf" to only "Aquire-Bold.otf"