Plugin.Maui.Theme
9.0.1
See the version list below for details.
dotnet add package Plugin.Maui.Theme --version 9.0.1
NuGet\Install-Package Plugin.Maui.Theme -Version 9.0.1
<PackageReference Include="Plugin.Maui.Theme" Version="9.0.1" />
<PackageVersion Include="Plugin.Maui.Theme" Version="9.0.1" />
<PackageReference Include="Plugin.Maui.Theme" />
paket add Plugin.Maui.Theme --version 9.0.1
#r "nuget: Plugin.Maui.Theme, 9.0.1"
#:package Plugin.Maui.Theme@9.0.1
#addin nuget:?package=Plugin.Maui.Theme&version=9.0.1
#tool nuget:?package=Plugin.Maui.Theme&version=9.0.1
🌈 Plugin.Maui.Theme
The Plugin.Maui.Theme
library provides a powerful theme management service for .NET MAUI applications, allowing dynamic switching of visual styles.
🔧 Class ThemeService
A singleton service that manages application themes via ResourceDictionary
.
📦 Properties and Fields
ThemeService.Current
: Static property to access the current instance._themes
: Dictionary containing registered themes (Dictionary<int, ResourceDictionary>
)._appResources
: Reference to the application'sMergedDictionaries
._currentDict
: Currently appliedResourceDictionary
._currentTheme
: Key-value pair representing the active theme.
🔑 Метод InitAppResources
Инициализирует ссылку на MergedDictionaries
приложения.
public void InitAppResources(ResourceDictionary resource)
💥Throws ArgumentNullException if the resource is null.
🎨 Method AddTheme
Registers a theme in the collection.
public void AddTheme(int key, ResourceDictionary theme, bool isDefault = false)
- key: Unique identifier for the theme.
- theme: ResourceDictionary defining the theme.
- isDefault: If true, sets the theme as the default.
🔄 Method ChangeTheme
Switches the application to the specified theme.
public void ChangeTheme(int key)
🧯 Throws exceptions if the theme is not found or InitAppResources was not called.
⚙️ Method InitService
Finalizes service setup.
public void InitService()
- If the theme is already in MergedDictionaries, it becomes active.
- Otherwise, the default or first available theme is applied.
📡 Event ThemeChanged
Triggered whenever the theme is changed:
public event EventHandler<ThemeChangedEventArgs>? ThemeChanged;
- Arguments include KeyTheme and NewTheme.
🧾 Record ThemeChangedEventArgs
public record ThemeChangedEventArgs(int KeyTheme, ResourceDictionary NewTheme);
Used to notify subscribers about theme changes.
✅ Usage Example
In the App.xaml.cs
class, you can use ThemeService
like this:
protected override Window CreateWindow(IActivationState? activationState)
{
ThemeService.Current.InitAppResources(Resources);
ThemeService.Current.AddTheme(0, new BlueTheme());
ThemeService.Current.AddTheme(1, new DarkTheme());
ThemeService.Current.AddTheme(2, new RedTheme(), true);
ThemeService.Current.InitService();
ThemeService.Current.ThemeChanged += Current_ThemeChanged;
return new Window(new AppShell());
}
🧠 Highlights
- Supports multiple themes.
- Enables dynamic switching.
- Event-driven UI updates.
🛠 Author: Fishman 📅 Last updated: July 2025
📄 License
This project is licensed under the Boost Software License – Version 1.0 – August 17th, 2003.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0-android35.0 is compatible. net9.0-ios18.0 is compatible. net9.0-maccatalyst18.0 is compatible. net9.0-windows10.0.26100 is compatible. net10.0-android was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-windows was computed. |
-
net9.0-android35.0
- Microsoft.Maui.Controls (>= 9.0.51)
-
net9.0-ios18.0
- Microsoft.Maui.Controls (>= 9.0.51)
-
net9.0-maccatalyst18.0
- Microsoft.Maui.Controls (>= 9.0.51)
-
net9.0-windows10.0.26100
- Microsoft.Maui.Controls (>= 9.0.51)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Plugin.Maui.Theme is a lightweight and extendable library for managing application-wide themes in .NET MAUI. It provides a centralized ThemeService that registers and switches between ResourceDictionary instances at runtime, allowing developers to apply styles dynamically without restarting the app.
The service tracks the current theme, supports initialization from existing resources, and raises a ThemeChanged event to help update the UI responsively. With a clean API and strict null checks, Plugin.Maui.Theme simplifies adaptive styling across platforms and is designed for easy integration with MVVM-based architectures and custom UI flows.