Skip to content

Theming (Phase 3)

This document explains how themes are switched at runtime using the token-generated resource dictionaries.

Components

  • Tokens and Palettes: generated XAML in src/SmrtHub.UI/Themes/
  • IThemeService (SmrtHub.UI): exposes CurrentTheme, ThemeChanged, and URIs for merged dictionaries.

Usage (WinUI 3)

// App.xaml.cs (pseudo-code)
var themeService = new ThemeService();

// Apply initial dictionaries
foreach (var uri in themeService.GetCurrentThemeResourceUris())
{
    App.Current.Resources.MergedDictionaries.Add(new Microsoft.UI.Xaml.ResourceDictionary
    {
        Source = new Uri(uri)
    });
}

// Respond to runtime theme changes
themeService.ThemeChanged += (_, e) =>
{
    // Replace palette dictionary (keep tokens & typography constant)
    // In practice: remove old palette dictionary and insert the new one at same index.
};

Notes: - Pack URIs resolve to embedded resources in SmrtHub.UI. - Tokens and Typography remain shared across themes; only the palette changes at runtime. - The app shell is currently excluded from default solution to keep builds green until tooling issues are resolved.