Search code examples
c#wpfxamlmaterial-design-in-xamldynamicresource

There is some way to overwrite the MaterialDesignPaper brush


I have a WPF application with MaterialDesign for XAML: https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit

I was able to verify that the MaterialDesignPaper brush changes dynamically when you change the mode (light,dark), But I want to change the color for the light theme.

There is some way to override or change the color of the brush only for the light theme, and keep its color change property?


Solution

  • You can check the Brush names as mentioned Here

    Example:

    • PrimaryHueLightBrush
    • PrimaryHueLightForegroundBrush
    • PrimaryHueMidBrush

    And so on..

    Create your custom as shown here

    <SolidColorBrush x:Key="PrimaryHueLightBrush" Color="#744CE0"/>
    <SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="#FFFFFF"/>
    <SolidColorBrush x:Key="PrimaryHueMidBrush" Color="#6134D9"/>
    ....
    

    Arbitrary colors in backend C# code

    using MaterialDesignThemes.Wpf;
    using System.Windows.Media;
    ...
    Color primaryColor = Colors.Purple;
    Color secondaryColor = Colors.Lime;
    
    IBaseTheme baseTheme = Theme.Light;
    //If you want a dark theme you can use IBaseTheme baseTheme = Theme.Dark;
    
    ITheme theme = Theme.Create(baseTheme, primaryColor, secondaryColor);
    

    You can get more info on themes, palettes and brushes on their Wiki page