admin管理员组

文章数量:1129046

Sometimes the MAUI splash image stops showing and fonts stop loading upon build.

Instead of the splash image set in the project file, the screen is filled with the "primary" color set in resources. Instead of the fonts loading in MauiProgram.cs, some default font is displayed through the entire application.

The issue can be solved temporarily, at least for the next build. I have to go to the properties of the splash image and font files, to change the Build Action to something else and back to normal again.

Does anybody know why this happens and how to solve this?

Notice
Not sure if there's any link but it seems to happen right after adding a new MAUI page. VS then keeps popping up an error that InitializeComponent does not exist in the current context, yet the app will build fine (in debug). This is often the same time the Build Action bug occurs.

Fonts
These are the font declarations I'm talking about, as set in MauiProgram.cs

var builder = MauiApp.CreateBuilder();
builder
    .UseMauiApp<App>()
    .UseMauiCommunityToolkit()
    .UseDevExpress()
    .UseSkiaSharp()
    .ConfigureFonts(fonts =>
    {
        fonts.AddFont("PtSansR.ttf", "PTSansRegular");
        fonts.AddFont("PtSansB.ttf", "PTSansBold");
        fonts.AddFont("PtSansI.ttf", "PTSansItalic");
        fonts.AddFont("PtSansBi.ttf", "PTSansBoldItalic");
        fonts.AddFont("GenBkBasR.ttf", "GentiumBookBasicRegular");
        fonts.AddFont("GenBkBasB.ttf", "GentiumBookBasicBold");
        fonts.AddFont("GenBkBasI.ttf", "GentiumBookBasicItalic");
        fonts.AddFont("GenBkBasBi.ttf", "GentiumBookBasicBoldItalic");
    });

Splash
This is the splash screen declaration...

<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#ffffff" BaseSize="256,256" />

Images
These are some of the image folder declarations in my project file...

<MauiImage Include="Resources\Images\*" />
<MauiImage Include="Resources\Images\Action\*" />
<MauiImage Include="Resources\Images\Container\*" />
<MauiImage Include="Resources\Images\Icons\*" />
<MauiImage Include="Resources\Images\Info\*" />
<MauiImage Include="Resources\Images\Popup\*" />
<MauiImage Include="Resources\Images\Support\*" />
<MauiImage Update="Resources\Images\brand.png" Resize="True" BaseSize="168,208" />

Packages I'm using the following packages, which may have something to do with this or not...

<ItemGroup>
    <PackageReference Include="CommunityToolkit.Maui" Version="8.0.1" />
    <PackageReference Include="CommunityToolkit.Maui.Core" Version="8.0.1" />
    <PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
    <PackageReference Include="DevExpress.Maui.Charts" Version="23.2.6" />
    <PackageReference Include="DevExpress.Maui.Controls" Version="23.2.6" />
    <PackageReference Include="DevExpress.Maui.Core" Version="23.2.6" />
    <PackageReference Include="DevExpress.Maui.Editors" Version="23.2.6" />
    <PackageReference Include="DevExpress.Maui.Gauges" Version="23.2.6" />
    <PackageReference Include="DevExpress.Maui.Scheduler" Version="23.2.6" />
    <PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
    <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
    <PackageReference Include="OneSignalApi" Version="2.0.2" />
    <PackageReference Include="OneSignalSDK.DotNet" Version="5.1.3" />
    <PackageReference Include="Refractored.MvvmHelpers" Version="1.6.2" />
    <PackageReference Include="SkiaSharp.Extended.UI.Maui" Version="2.0.0" />
    <PackageReference Include="SkiaSharp.Views.Maui.Core" Version="2.88.8" />
    <PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
    <PackageReference Include="SQLiteNetExtensions" Version="2.1.0" />
    <PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.10" />
    <PackageReference Include="SQLitePCLRaw.provider.dynamic_cdecl" Version="2.1.10" />
    <PackageReference Include="SQLitePCLRaw.provider.sqlite3" Version="2.1.10" />
</ItemGroup>

本文标签: cMAUI splash screen and fonts not always loadedStack Overflow