An Introduction to Material Themes for WPF Applications
Tags: webdev, devops, dotnet
Published: 2024-02-02 18:48:41

---
canonical_url: https://developer.mescius.com/blogs/an-introduction-to-material-themes-for-wpf-applications
description: See how to apply a Material design look and feel to your entire .NET desktop application using ComponentOne WPF Edition.
---
The [<span>ComponentOne WPF Edition</span>](https://developer.mescius.com/componentone/wpf-ui-controls/office-design-themes-wpf "/componentone/wpf-ui-controls/office-design-themes-wpf") supports several built-in themes for .NET 6 and .NET 8 applications, including light and dark Material themes. Applying a material theme in your WPF application is as easy as:

1.  [Add Package Reference to C1.WPF.Themes.Material](#add)
2.  [Apply the Material Theme with Two Lines of Code](#apply)
3.  (Optional) [Customize the Material Theme Colors in XAML](#customize)

And that’s it! In this blog, we'll walk you through each of these steps to apply and customize a Material theme in a WPF .NET 8 application. Plus, explore the Material Theme Builder to help you design a brilliant color scheme.

## What is a WPF Material Theme

We designed our material theme following best practices defined by [<span>Material.io</span>](https://m3.material.io/ "https://m3.material.io/"). Material themes are not bound by a single color scheme, so we’ve made our WPF Material theme customizable in the easiest way possible: by simply defining colors in XAML.

By customizing our WPF material theme, you can choose a light or dark background and add a pop of accent color to match your application or company branding. Our WPF material theme even supports standard .NET controls.

![WPF Material Themes](//cdn.mescius.io/umb/media/q1fnutpq/01-wpf_themes_materialcustom.png?rmode=max&width=753&height=451)

### <a id="add"></a>Add Package Reference to C1.WPF.Themes.Material

First, decide if you want a light or dark background.

Then, add the latest 8.0* package **C1.WPF.Themes.Material** from nuget.org for the light material theme base. Or get the **C1.WPF.Themes.MaterialDark** package for the dark theme base.

![WPF Material Themes](//cdn.mescius.io/umb/media/0h4nyipu/02-wpf_material.png?rmode=max&width=750&height=342)

Note that this 8.0* package supports .NET 8, .NET 7, and .NET 6 WPF applications. If you need a .NET Framework, look for the C1.Xaml.WPF.Themes.Material package.

### <a id="apply"></a>Apply the Material Theme with Two Lines of Code

Open your MainWindow code behind, instantiate the C1Theme, and use the _Apply_ method to theme any specific FrameworkElement (i.e., a single control) or the entire Window using the code below.

```
    C1.WPF.Themes.C1ThemeMaterial myTheme = new C1.WPF.Themes.C1ThemeMaterial();
    myTheme.Apply(this); // applies theme to entire window
```

That’s it! You can also apply a theme to your entire application in one place. Read our previous blog, [<span>How to Add WPF Themes to Style Your Desktop Applications</span>](https://developer.mescius.com/blogs/how-to-add-wpf-themes-to-style-your-desktop-applications "/blogs/how-to-add-wpf-themes-to-style-your-desktop-applications"), to learn more.

### <a id="customize"></a>How to Customize the Material Theme Colors in XAML

Next, you can choose to modify the color scheme of the material theme. Add a Resource Dictionary XAML file and name it something like CustomTheme.xaml.

![WPF Material Themes](//cdn.mescius.io/umb/media/jrrph2po/03-wpfresourcedictionary.png?rmode=max&width=742&height=404)

In this file, we will override key brushes by names such as PrimaryColor, BackgroundColor, OnSurfaceColor, and others specific to menus, hyperlinks, and alternate colors. This is how we can easily customize the existing theme. Set the **build action of the dictionary to Embedded Resource** and copy in the XAML below as a starting point.

```
    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

        <!-- Color & Brush used to build Base brushes -->
        <Color x:Key="PrimaryColor">#a31688</Color>
        <Color x:Key="BackgroundColor">#1688a3</Color>
        <Color x:Key="OnSurfaceColor">White</Color>
        <SolidColorBrush x:Key="MenuHighlightBrush" Color="{StaticResource PrimaryColor}" Opacity="0.04"/>
        <SolidColorBrush x:Key="SubtotalBackground" Color="#0d5060" />
        <Color x:Key="SelectedColor">#026a81</Color>

        <!-- C1HyperLinkButton Foreground-->
        <SolidColorBrush x:Key="HyperLinkForeground" Color="#dafdf7" />
        <SolidColorBrush x:Key="IndicatorBrush" Color="#93edf1" />

        <SolidColorBrush x:Key="SliderThumb.Pressed.Background" Color="#026a81"/>
        <SolidColorBrush x:Key="SliderThumb.Pressed.Border" Color="#93edf1"/>

        <SolidColorBrush x:Key="FocusBrush" Color="{StaticResource SelectedColor}"/>
        <SolidColorBrush x:Key="AccentBrush" Color="{StaticResource PrimaryColor}"/>

    </ResourceDictionary>
```

The brush names are based on the [<span>material.io color system</span>](https://m3.material.io/styles/color/the-color-system/key-colors-tones "https://m3.material.io/styles/color/the-color-system/key-colors-tones"). If you need to customize more, you can find more brushes in the source XAML of our Material theme (installed to C:\Program Files (x86)\MESCIUS\ComponentOne\WPF\Resources\v8\C1WPFThemesMaterial)

Lastly, modify the code from above with a new overload that passes this CustomTheme.xaml file. You must pass in the assembly type and file name with a full namespace. In our sample called “MyProject” it would look like this below:

```
    myTheme = new C1ThemeMaterial(typeof(MyProject.App).Assembly, "MyProject.CustomTheme.xaml");
```

And that’s it! You can download the [<span>full sample here on GitHub</span>](https://github.com/GrapeCity/ComponentOne-WPF-Samples/tree/master/NET_6/Themes/ThemeExplorer "https://github.com/GrapeCity/ComponentOne-WPF-Samples/tree/master/NET_6/Themes/ThemeExplorer").

![WPF Material Themes](//cdn.mescius.io/umb/media/y1fmp1kf/04-wpf_custom_theme_teal_purple.png?rmode=max&width=748&height=389)

## How to Design a Good Material Design Color Scheme

If you are not a designer - do not worry! You can take advantage of the [<span>material.io Theme Builder</span>](https://m3.material.io/theme-builder#/custom "https://m3.material.io/theme-builder#/custom") to help.

Build a custom color scheme to map dynamic colors, use them as fallback colors, or implement a branded theme. The color system automatically handles critical adjustments that provide accessible color contrast. Use the colors output here as your primary and secondary on surface brushes.

![WPF Material Themes](//cdn.mescius.io/umb/media/kj0lkx5l/05-material_theme_builder.png?rmode=max&width=754&height=500)