How to change the color of WPF Material Design at runtime.
Material DesignのC#コードで実行中に色を変える方法です。LLM Doghouse内のコードを掲載します。
Chage Mode Dark/Light
private void SetBaseColors()
{
PaletteHelper palette = new PaletteHelper();
Theme theme = palette.GetTheme();
if (chkMod.IsChecked.Value)
{
theme.SetBaseTheme(BaseTheme.Light);
}
else
{
theme.SetBaseTheme(BaseTheme.Dark);
}
palette.SetTheme(theme);
}
Change Promary Color
private void SetPrimaryColors(int intPrm)
{
PaletteHelper palette = new PaletteHelper();
Theme theme = palette.GetTheme();
switch (intPrm)
{
case 0:
theme.SetPrimaryColor(SwatchHelper.Lookup[(MaterialDesignColor)PrimaryColor.Amber]);
break;
case 1:
theme.SetPrimaryColor(SwatchHelper.Lookup[(MaterialDesignColor)PrimaryColor.Blue]);
break;
case 2:
theme.SetPrimaryColor(SwatchHelper.Lookup[(MaterialDesignColor)PrimaryColor.BlueGrey]);
break;
case 3:
theme.SetPrimaryColor(SwatchHelper.Lookup[(MaterialDesignColor)PrimaryColor.Brown]);
break;
}
palette.SetTheme(theme);
}