Comments (3)
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.
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.
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)
- Wrong size and wrong 'look and feel' for ToggleButton with Style="{StaticResource MaterialDesignSwitchToggleButton}" HOT 3
- Improve Snackbar feature so that multiple messages can display simultaneously HOT 2
- DataGrid Scrollbar column header not stylized
- powershell mahapps metro material design integration
- TreeListViewItem does not mark KeyEvents as handled
- DialogHost: XamlObjectWriterException - Unresolved reference 'ContentCoverBorder' HOT 3
- Need to update website HOT 1
- Can not be used under Wndows 2016 Standard HOT 3
- ColorReference does not contain any color HOT 1
- Event Handler Leak on every button click - System.Windows.VisualStateManager+<>c__DisplayClass12_0 HOT 2
- XamlParseException: InverseBoolToVisConverter - commit (#3515)
- SmartHint is clipped when FloatingScale > 1
- AutoSuggestBox crashes (demo) application
- DatePicker / TimePicker hover effect is lost when hovering calendar/time button
- SplitButton style HOT 3
- cant apply any style HOT 1
- Update the wiki: Broken Links in Project Wiki HOT 3
- MVVM使用SnackbarMessageQueue导致不能被GC(内存泄露) HOT 1
- Suggest adding a multi selection combo box control
- Demo, Information Links URL not correct HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from materialdesigninxamltoolkit.