6

I'm using MudBlazor v6.07 and I know how to change the individual colors of the (UI) components using a new theme and code like this:

private MudTheme _myTheme= new MudTheme();
_myTheme.Palette.Primary = new MudBlazor.Utilities.MudColor("#090");

But I would like to switch to one of the palettes at once, like Green or Pink. Instead of modifying each theme color one by one.

I assume this can be done, but I can't find how to do this.

Paul Meems
  • 3,002
  • 4
  • 35
  • 66

1 Answers1

7

You can pass in the theme you want as a variable and then you can change it via code..

<MudThemeProvider Theme="@MyCustomTheme" />

@code {
  MudTheme MyCustomTheme = new MudTheme()
    {
        Palette = new Palette()
        {
            Primary = Colors.Blue.Darken4,
            Secondary = Colors.Green.Accent4,
            AppbarBackground = Colors.Red.Default,
            //Define other properties here.  
        },
        
    };
}

There is a section about this in the documentation.

Saeed Prez
  • 728
  • 3
  • 8
  • Thanks for your reply. I'm aware of that page. I already use that to change individual components. But I want to change all components at once by setting a different color palette. – Paul Meems Mar 24 '22 at 15:07
  • 2
    I made an example for you, perhaps this will be more clear: https://try.mudblazor.com/snippet/wEQGuxmSgOWqxkyq Note that you'll have to change the main theme provider, i.e. the one in your layout. – Saeed Prez Mar 24 '22 at 16:52
  • As a note, there is no built in way to retrieve a Palette from a config file. But you can always roll your own. In other words, create a section in AppSetting.json and then get that at runtime and use it to define the Palette for the Theme. – Greg Gum Jan 09 '23 at 02:17