Coder Social home page Coder Social logo

Comments (3)

jbooth88 avatar jbooth88 commented on June 5, 2024 1

I don't know if it's the "right way", but try this

var newTheme = _darkTheme ? BaseTheme.Dark : BaseTheme.Light;
var colorKey = nameof(MaterialDesignColor.DeepPurple);
var swatchProvider = new SwatchesProvider();
var swatch = swatchProvider.Swatches.FirstOrDefault(x => string.Equals(x.Name, colorKey, StringComparison.OrdinalIgnoreCase));
if (swatch != null)
{
    var paletteHelper = new PaletteHelper();
    var theme = paletteHelper.GetTheme();
    theme.SetBaseTheme(newTheme);
    theme.SetPrimaryColor(swatch.ExemplarHue.Color);
    theme.SetSecondaryColor(swatch.SecondaryExemplarHue?.Color ?? swatch.ExemplarHue.Color); //nullable SecondaryExemplarHue? I don't know what to do here.
    paletteHelper.SetTheme(theme);
}

from materialdesigninxamltoolkit.

Keboo avatar Keboo commented on June 5, 2024 1

It is actually slightly easier to do in the 5.0 release.

You still need to get an instance of the Theme. This will typically be done with PaletteHelper.GetTheme() or the GetTheme() extension method on ResourceDictionary. Once you have that theme instance you can switch between Light/Dark themes simply by calling SetDarkTheme()/SetLightTheme() directly on it, which will update the internal brushes with the corresponding values. Finally, to apply the theme, you will need to call PaletteHelper.SetTheme(Theme) or more generically the SetTheme() extension method on ResourceDictionary.

from materialdesigninxamltoolkit.

Jonesie avatar Jonesie commented on June 5, 2024

Thanks people :)

This works:

var ph = new PaletteHelper();
var theme = ph.GetTheme();
if (theme != null)
{
  if (_darkTheme)
    theme.SetDarkTheme();
  else
    theme.SetLightTheme();
  ph.SetTheme(theme);
}

from materialdesigninxamltoolkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.