# Themes and design tokens

Give the app a consistent palette, spacing rhythm, and typography. A design-system provider lets widgets share those choices instead of each button inventing its own color and padding.

## Put the provider above the controls

`DesignSystemView` accepts a content view and optional `XuiDesignSystemOptions`. The [preferences example](../widgets/index.md) uses the default Xui options. The starter places one provider around its navigation shell, so destinations can resolve the same theme.

This constructor-body fragment changes the seed options for an existing `page` view:

```csharp
var themed = new Xui.ToolKit.UI.Design.DesignSystemView(page,
    new Xui.ToolKit.UI.Design.XuiDesignSystemOptions
    {
        PrimaryHue = 280,
        SecondaryHue = 320,
        Chroma = (System.Runtime.InteropServices.NFloat)0.18,
        DefaultFontFamily = "Inter",
        Sizing = Xui.ToolKit.UI.Design.SizingPreset.Mobile
    });
```

Add `themed` to your view tree in place of `page`; a view cannot belong to two parents. Supplying options replaces the provider's default option selection, including its device-based sizing choice.

## Work with semantic tokens

`IDesignSystem` exposes color, typography, spacing, shape, and motion systems. Choose a color role according to meaning, such as primary action or error, rather than copying the current purple value into every control.

Core `Label` does not automatically become themed because a provider is present. It exposes explicit font and text-color properties. If a custom view should follow theme changes, resolve the design service, read the relevant tokens, and subscribe for the active lifetime of the view.

## React to changes at the right cost

`DesignSystemView` creates its design system during activation when `IDeviceInfo` is available. It observes device preference changes and updates the retained system. Token change notifications identify affected groups.

A palette change needs a redraw. Typography or spacing can change measurement and arrangement as well. Custom consumers should request the corresponding invalidation and unsubscribe when inactive; otherwise a retained provider can keep an old page alive.

The device contract exposes color scheme, accessibility font scale, reduced motion, and high contrast. Runtimes supply these values with differing completeness. Using the contract is a good starting point, not proof that every host receives every operating-system notification.

Try the default theme in light and dark environments and with larger text. Check explicit Core text colors against the surrounding themed surfaces: a hardcoded black label on a dark surface is still your responsibility.
