Replies: 1 comment
-
You will probably want to create a class library project. Instead of "BaseApp" perhaps name it as "MyLibrary". With the fonts, say, you can make it an embedded resource of your class library, e.g.
Then, in both App1 and App2 you will need to update their respective MauiProgram.cs so that it calls AddEmbededResourceFont so that it finds the font resource from the class library. .ConfigureFonts(fonts =>
{
//fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
var assembly = Assembly.GetAssembly(typeof(MyLibrary)); // Replace with a reliable way to access your class library's assembly
fonts.AddEmbededResourceFont(assembly, "OpenSans-Regular.ttf", "OpenSansRegular");
}); You can take this one step further and offer a MauiAppBuilder extension method in your class library: namespace MyLibrary;
public static partial class MyLibraryAppBuilderExtensions
{
public static MauiAppBuilder UseMyLibrary(this MauiAppBuilder builder)
{
builder.ConfigureFonts(fonts =>
{
var assembly = Assembly.GetAssembly(typeof(MyLibraryAppBuilderExtensions));
fonts.AddEmbededResourceFont(assembly, "OpenSans-Regular.ttf", "OpenSansRegular");
}
return builder;
}
} Then in App1 and App2 they only need to call UseMyLibrary's extension method, e.g. public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMyLibrary()
/* ... */ |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
We need App1 and App2 to seamlessly access and utilize resources from BaseApp, including:
common resources (Styles, Colors,)
Platform-specific resources (Android drawables, iOS assets)
Any proven approaches to share resources across multiple MAUI applications?
I tried using link but when compiling it always says that the file cannot be found
Beta Was this translation helpful? Give feedback.
All reactions