AathifMahir.Maui.MauiTheme 0.1.1-preview

Prefix Reserved
This is a prerelease version of AathifMahir.Maui.MauiTheme.
There is a newer version of this package available.
See the version list below for details.
dotnet add package AathifMahir.Maui.MauiTheme --version 0.1.1-preview                
NuGet\Install-Package AathifMahir.Maui.MauiTheme -Version 0.1.1-preview                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AathifMahir.Maui.MauiTheme" Version="0.1.1-preview" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AathifMahir.Maui.MauiTheme --version 0.1.1-preview                
#r "nuget: AathifMahir.Maui.MauiTheme, 0.1.1-preview"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AathifMahir.Maui.MauiTheme as a Cake Addin
#addin nuget:?package=AathifMahir.Maui.MauiTheme&version=0.1.1-preview&prerelease

// Install AathifMahir.Maui.MauiTheme as a Cake Tool
#tool nuget:?package=AathifMahir.Maui.MauiTheme&version=0.1.1-preview&prerelease                

Maui Theme

Latest Stable Latest Preview
AathifMahir.Maui.MauiShakeDetector AathifMahir.Maui.MauiShakeDetector

MauiTheme is Theming Libray that Makes the Theming on Dotnet Maui a Breeze with Persistent Theme State Between Sessions and Seamless Resource Swapping, Theme Switcher and etc..

Get Started

You need to Call InitializeTheme() in the App.xaml.cs Like Below Example

public partial class App : Application
{
    public App()
    {
        InitializeComponent();

        MainPage = new AppShell();

        Theme.Default.InitializeTheme<App>(x =>
        {
            // Default Theme
            x.DefaultTheme = MauiAppTheme.Dark;
            // Default Styles Resources
            x.DefaultStyleResources = ["Resources/Styles/Styles.xaml"];
            // All Resources Excluding Styles
            x.Resources = new()
                {
                    {"Blue", "Resources/Styles/Blue.xaml"},
                    {"Purple", "Resources/Styles/Colors.xaml"},
                    {"Yellow", "Resources/Styles/Yellow.xaml" },
                    {"Green", "Resources/Styles/Green.xaml" }
                };
            
        });

    }
}

App.xaml Setup

The App.xaml should include the Default Color and Style Resource Like Below Example

<Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
            
                <ResourceDictionary Source="Resources/Styles/Yellow.xaml" />
                <ResourceDictionary Source="Resources/Styles/Styles.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
</Application.Resources>

Initialize Properties

Parameters Type Description
DefaultTheme enum The Default Theme, if the Theme is Previously Not Assigned by User
DefaultStyleResources Dictionary<string, string> The Default Style Resources that Needs to Applied with Every Resource Change Eg: Styles.xaml
Resources Dictionary<string, string> All Resources in the Project Excluding Style Resources

Theme

When it comes to Switching Theme, You can change the CurrentTheme Property to Switch the Theme Like Below Example


// Dark
Theme.Default.CurrentTheme = MauiAppTheme.Dark;

// Light
Theme.Default.CurrentTheme = MauiAppTheme.Light;

// System
Theme.Default.CurrentTheme = MauiAppTheme.UnSpecified;

Resources

When it comes to Switching Resource, You can use CurrentResource Property to Swap the Resources Like Below Example, Make sure to Note that Resources is Applied Using The Key that you have passed into InitializeTheme Resources Property


// Blue.xaml
Theme.Default.CurrentResource = "Blue";

// Purple.xaml
Theme.Default.CurrentResource = "Purple";

// Yellow.xaml
Theme.Default.CurrentResource = "Yellow";

Listening to Theme or Resource Changes

Mainly this is useful when theme or resource changes is invoked from external source for instance from a razor class library


// Theme Changed Event
MauiTheme.Default.ThemeChanged += (s, t) => 
{
    Debug.Writeline($"New Theme : {t.ToString()}")
}

// Theme Changed Event
MauiTheme.Default.ResourceChanged += (s, r) => 
{
    Debug.Writeline($"New Resource : {r}")
}

Additionally we can use ICommand as well, Those are ThemeChangedCommand and ResourceChangedCommand

License

Maui Theme is Licensed Under MIT License.

Contribute and Credit

Credits for @taublast for Helping with Resource Creation.

If you wish to contribute to this project, please don't hesitate to create an issue or request. Your input and feedback are highly appreciated. Additionally, if you're interested in supporting the project by providing resources or becoming a sponsor, your contributions would be welcomed and instrumental in its continued development and success. Thank you for your interest in contributing to this endeavor.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-android33.0 is compatible.  net7.0-ios was computed.  net7.0-ios16.1 is compatible.  net7.0-maccatalyst was computed.  net7.0-maccatalyst16.1 is compatible.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net7.0-windows10.0.19041 is compatible.  net8.0 is compatible.  net8.0-android was computed.  net8.0-android34.0 is compatible.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-ios17.0 is compatible.  net8.0-maccatalyst was computed.  net8.0-maccatalyst17.0 is compatible.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net8.0-windows10.0.19041 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.5.0 228 1/21/2024
0.1.1-preview 137 1/16/2024
0.1.0-preview 102 1/16/2024
0.0.1-preview 109 1/8/2024

v0.1.0-preview
• Enhancements and Fixes
• Breaking Changes on Maui Built in AppTheme Construct, Now MauiTheme Uses Custom Construct Called MauiAppTheme

v0.0.1-preview
• Initial Preview Version