-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Advanced Theming
The information here applies to version 5.0.0 and later.
The first step is to set the initial theme. There are two recommended ways to accomplish this:
- Use one of the built in Markup Extensions that generates a theme resource dictionary. Use one of the built-in markup extensions (
BundledTheme
orCustomColorTheme
). These return a newResourceDictionary
instance with all of the brushes setup for you. - Create a new
Theme
object and useResourceDictionaryExtensions.SetTheme(Application.Current.Resources)
. You can create a newTheme
object using:
using MaterialDesignColors;
using MaterialDesignThemes.Wpf;
using System.Windows.Media;
...
Theme theme = new();
PrimaryColor primary = PrimaryColor.DeepPurple;
Color primaryColor = SwatchHelper.Lookup[(MaterialDesignColor)primary];
theme.SetPrimaryColor(primaryColor);
SecondaryColor secondary = SecondaryColor.Teal;
Color secondaryColor = SwatchHelper.Lookup[(MaterialDesignColor)secondary];
theme.SetSecondaryColor(secondaryColor);
theme.SetLightTheme();
//If you want a dark theme you can use theme.SetDarkTheme(); or theme.SetBaseTheme()
If you want you can use any arbitrary colors.
Theme theme = new();
Color primaryColor = Colors.Purple;
theme.SetPrimaryColor(primaryColor);
Color secondaryColor = Colors.Lime;
theme.SetSecondaryColor(secondaryColor);
theme.SetLightTheme();
//If you want a dark theme you can use theme.SetDarkTheme(); or theme.SetBaseTheme()
To change the theme simply get or create a Theme
instance, modify this theme instance, and then apply it with PaletteHelper.SetTheme
. Similar to this:
using MaterialDesignColors;
using MaterialDesignThemes.Wpf;
...
var paletteHelper = new PaletteHelper();
//Retrieve the app's existing theme
Theme theme = paletteHelper.GetTheme();
//Change the base theme to Dark
theme.SetBaseTheme(BaseTheme.Dark);
//or theme.SetBaseTheme(Theme.Light);
//Change all of the primary colors to Red
theme.SetPrimaryColor(Colors.Red);
//Change all of the secondary colors to Blue
theme.SetSecondaryColor(Colors.Blue);
//You can also change a single color on the theme, and optionally set the corresponding foreground color
theme.PrimaryMid = new ColorPair(Colors.Brown, Colors.White);
//Change the app's current theme
paletteHelper.SetTheme(theme);
If you see any mistake or want to contribute to this wiki feel free.
Home
Contributing
Compiling From Source
Glossary
Getting Started with MDIX
Getting Started
Tutorial On YouTube (português-BR)
Frequently Asked Questions
Examples Repository
Release Notes
Pack Icon Changes
2.0.0 Breaking Changes
Controls
All Control Styles
Buttons
ComboBox
Dialogs
PopupBox
Snackbar
TextBox
Toggle Button
Transitions
Icons
Theming
Advanced Theming
Brush Names
Custom Palette Hues
Fonts
Overriding Material Design Styles
Swatches and Recommended Colors
Miscellaneous
MahApps Integration
Performance
Strong Naming
.NET 4.0 Compatibility
Projects using Material Design
Understanding Routed Commands