Repository navigation
Usage
Andreas edited this page Jan 13, 2023
·
3 revisions
In order to access the Resources from the library, merge the theme into your Application.ResourceDictionary.
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:AppBasement"
xmlns:themes="clr-namespace:AppBasement.Themes"
x:Class="AppBasement.App"
>
<Application.Resources>
<themes:DefaultTheme />
</Application.Resources>
</Application>The DefaultTheme
<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="AppBasement.Themes.DefaultTheme"
xmlns:shared="clr-namespace:AndreasReitberger.Shared;assembly=SharedMauiXamlStylesLibrary"
>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Themes/DefaultColors.xaml" />
<!-- Item Templates -->
<ResourceDictionary Source="/Themes/ItemTemplates/ListViewGroupHeaderTemplates.xaml" />
<ResourceDictionary Source="/Themes/ItemTemplates/ListViewHeaderTemplates.xaml" />
<ResourceDictionary Source="/Themes/ItemTemplates/ListViewItemTemplates.xaml" />
<!-- Additional Control Styles -->
<ResourceDictionary Source="/Themes/Controls/Core/SearchableListView.xaml" />
<ResourceDictionary Source="/Themes/Controls/Syncfusion/SfBusyIndicator.xaml" />
<!-- Override colors -->
<shared:DefaultTheme/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>Note
At the moment there is a bug for .NET MAUI libraries which does not make the StaticResources available in InteliSense.
https://github.com/dotnet/maui/issues/10112
It's recommended to include the whole project into your app, not the nuget.
All used fonts are available from the SharedFonts.Fonts property.
public class SharedFonts
{
#region Properties
public static Dictionary<string, string> Fonts = new()
{
{ "FontAwesome5Brands.otf", "FontAwesome5Brands" },
{ "FontAwesome5Regular.otf", "FontAwesome5Regular" },
{ "FontAwesome5Solid.otf", "FontAwesome5Solid" },
{ "materialdesignicons-webfont.ttf", "MaterialDesignIcons" },
{ "Montserrat-Bold.ttf", "MontserratBold" },
{ "Montserrat-Medium.ttf", "MontserratMedium" },
{ "Montserrat-Regular.ttf", "MontserratRegular" },
{ "Montserrat-SemiBold.ttf", "MontserratSemiBold" },
{ "UIFontIcons.ttf", "UIFontIcons" },
};
#endregion
}In order to initialize the style library and to register all shared fonts, add following function to the MauiAppBuilder. Used Fonts
public static MauiApp CreateMauiApp()
{
MauiAppBuilder builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiApp<App>().UseMauiCommunityToolkit()
.ConfigureFonts(fonts =>
{
// Your own used fonts
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
})
// Initializes library and shared fonts (for list of used fonts, see above)
..InitializeSharedMauiStyles()
;
}