Overview
DaisyThemeManager is the centralized theme manager for DaisyUI themes in Uno/WinUI applications. It swaps palette ResourceDictionary instances into Application.Resources.MergedDictionaries and raises theme change events.
Methods
ApplyTheme
public static bool ApplyTheme(string themeName)
Applies a theme by name. Returns true if successful, false if the theme name is invalid or application.
The name of the theme to apply (e.g., “Dark”, “Synthwave”, “Light”)
true if the theme was applied successfully; false otherwise
Example:
using Flowery.Controls;
// Apply the Synthwave theme
DaisyThemeManager.ApplyTheme("Synthwave");
// Check if successful
if (DaisyThemeManager.ApplyTheme("Dracula"))
{
Console.WriteLine("Theme applied!");
}
RegisterTheme
public static void RegisterTheme(DaisyThemeInfo info, Func<ResourceDictionary> paletteFactory)
Registers a custom theme with a palette factory. Use this to add custom themes beyond the built-in DaisyUI themes.
Theme information containing name and whether it’s a dark theme
paletteFactory
Func<ResourceDictionary>
required
Factory function that creates the theme’s palette ResourceDictionary
Example:
using Flowery.Controls;
using Flowery.Theming;
// Register a custom theme
var customTheme = new DaisyThemeInfo("MyCustomTheme", isDark: true);
DaisyThemeManager.RegisterTheme(
customTheme,
() => DaisyPaletteFactory.Create("MyCustomTheme")
);
GetThemeInfo
public static DaisyThemeInfo? GetThemeInfo(string themeName)
Retrieves theme information by name.
The name of the theme to retrieve
Theme info object if found, or null if the theme doesn’t exist
Example:
var info = DaisyThemeManager.GetThemeInfo("Dracula");
if (info != null)
{
Console.WriteLine($"Theme: {info.Name}, Dark: {info.IsDark}");
}
IsDarkTheme
public static bool IsDarkTheme(string themeName)
Checks whether a theme is a dark theme.
The name of the theme to check
true if the theme is dark; false otherwise
Example:
bool isDark = DaisyThemeManager.IsDarkTheme("Dracula"); // true
bool isLight = DaisyThemeManager.IsDarkTheme("Cupcake"); // false
SetCurrentTheme
public static void SetCurrentTheme(string themeName)
Sets the current theme name and fires the ThemeChanged event. Used by custom theme applicators to update internal state after applying a theme.
The name of the theme that was applied
Example:
// After applying theme via custom logic
DaisyThemeManager.SetCurrentTheme("MyCustomTheme");
Properties
CurrentThemeName
public static string? CurrentThemeName { get; }
Gets the currently active theme name.
Example:
var current = DaisyThemeManager.CurrentThemeName;
Console.WriteLine($"Current theme: {current}");
AvailableThemes
public static ReadOnlyCollection<DaisyThemeInfo> AvailableThemes { get; }
Gets a read-only collection of all available themes. Includes all 36 DaisyUI themes plus any custom registered themes.
Example:
foreach (var theme in DaisyThemeManager.AvailableThemes)
{
Console.WriteLine($"{theme.Name} (Dark: {theme.IsDark})");
}
BaseThemeName
public static string BaseThemeName { get; set; }
Gets or sets the base/default theme name. Used by theme controllers as the “unchecked” theme. Defaults to "Dark".
Example:
// Set default theme
DaisyThemeManager.BaseThemeName = "Light";
AlternateThemeName
public static string AlternateThemeName { get; }
Gets the “alternate” theme - returns the current theme if it’s not the base theme, otherwise returns "Dark" as a fallback.
Example:
var alternate = DaisyThemeManager.AlternateThemeName;
Console.WriteLine($"Alternate theme: {alternate}");
SuppressThemeApplication
public static bool SuppressThemeApplication { get; set; }
When true, ApplyTheme calls only update internal state without actually applying the theme. Useful for testing or custom theme application logic.
Example:
// Temporarily suppress theme application
DaisyThemeManager.SuppressThemeApplication = true;
DaisyThemeManager.ApplyTheme("Dark"); // Updates state only
DaisyThemeManager.SuppressThemeApplication = false;
CustomThemeApplicator
public static Func<string, bool>? CustomThemeApplicator { get; set; }
Optional custom theme applicator delegate. When set, this function is called instead of the default MergedDictionaries approach.
Example:
// Set custom theme application logic
DaisyThemeManager.CustomThemeApplicator = (themeName) =>
{
// Custom logic here
Console.WriteLine($"Applying {themeName}");
return true;
};
Events
ThemeChanged
public static event EventHandler<string>? ThemeChanged
Event raised when the theme changes. The event args contain the new theme name.
Example:
DaisyThemeManager.ThemeChanged += (sender, themeName) =>
{
Console.WriteLine($"Theme changed to: {themeName}");
// Save preference
SaveThemePreference(themeName);
};
Complete Example
using Flowery.Controls;
using Microsoft.UI.Xaml;
public class ThemeService
{
public ThemeService()
{
// Subscribe to theme changes
DaisyThemeManager.ThemeChanged += OnThemeChanged;
}
public void Initialize()
{
// Load saved theme or use default
var savedTheme = LoadThemeFromSettings() ?? "Dark";
DaisyThemeManager.ApplyTheme(savedTheme);
}
public void ToggleTheme()
{
var currentTheme = DaisyThemeManager.CurrentThemeName;
var isDark = DaisyThemeManager.IsDarkTheme(currentTheme ?? "Dark");
// Switch between light and dark
var newTheme = isDark ? "Light" : "Dark";
DaisyThemeManager.ApplyTheme(newTheme);
}
public void ListAllThemes()
{
foreach (var theme in DaisyThemeManager.AvailableThemes)
{
Console.WriteLine($"{theme.Name} (Dark: {theme.IsDark})");
}
}
private void OnThemeChanged(object? sender, string themeName)
{
// Persist theme preference
SaveThemeToSettings(themeName);
// Update UI
Console.WriteLine($"Theme changed to: {themeName}");
}
private string? LoadThemeFromSettings() { /* ... */ return null; }
private void SaveThemeToSettings(string theme) { /* ... */ }
}
DaisyThemeInfo
public partial class DaisyThemeInfo
{
public string Name { get; }
public bool IsDark { get; }
}
Contains information about a theme, including its name and whether it’s a dark theme.
Best Practices
- Apply theme before UI construction - Call
ApplyTheme in your App.OnLaunched before creating windows
- Subscribe to ThemeChanged - Use the event to persist user preferences
- Use ThemeResource bindings - Always use
{ThemeResource} instead of {StaticResource} for theme colors in XAML
- Check return values -
ApplyTheme returns false if the theme doesn’t exist
Available Themes
Flowery.Uno includes all 36 official DaisyUI themes plus Happy Hues themes:
Light Themes: Light, Acid, Autumn, Bumblebee, Caramellatte, Cmyk, Corporate, Cupcake, Cyberpunk, Emerald, Fantasy, Garden, Lemonade, Lofi, Nord, Pastel, Retro, Silk, Valentine, Winter, Wireframe
Dark Themes: Dark, Abyss, Aqua, Black, Business, Coffee, Dim, Dracula, Forest, Halloween, Luxury, Night, Smooth, Sunset, Synthwave
Happy Hues Themes: HappyHues01-17