Skip to content

PaletteHelper doesn't work anymore #2432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kacciocciacciara opened this issue Sep 23, 2021 · 9 comments
Closed

PaletteHelper doesn't work anymore #2432

kacciocciacciara opened this issue Sep 23, 2021 · 9 comments
Labels
question Old items with this tag will be automatically closed.

Comments

@kacciocciacciara
Copy link

kacciocciacciara commented Sep 23, 2021

I have the following snippet of code that updates my base theme:

PaletteHelper paletteHelper = new PaletteHelper();
ITheme theme = paletteHelper.GetTheme();
theme.SetBaseTheme(Settings.Interface.UseDarkTheme ? Theme.Dark : Theme.Light);
paletteHelper.SetTheme(theme);

version 4.1.0 - working
update to 4.2.1 - not working
rollback to 4.1.0 - working

In the new version, my application starts with the light theme and never updates to dark.

@Keboo
Copy link
Member

Keboo commented Sep 23, 2021

Hi @kacciocciacciara are you able to share more information about your code. I am not currently able to replicate the issue.

Can you confirm that you are seeing the Settings.Interface.UseDarkTheme change from true to false?

@Keboo Keboo added the Waiting on feedback Additional information is needed. Stale items with this label may be closed. label Sep 23, 2021
@kacciocciacciara
Copy link
Author

Yes, I can confirm.
It's the first thing I thought it could be the cause, but the boolean value updates correctly.
There aren't any errors nor exceptions, it looked like the SetTheme method did nothing.

@Keboo
Copy link
Member

Keboo commented Sep 25, 2021

@kacciocciacciara are you able to share the project? I am not able to replicate the issue.

@kacciocciacciara
Copy link
Author

Hi @Keboo
unfortunately, I can't. It's a project I'm working for my company and I can't share any source.
I'm inclined to think that the issue is within my code and not in the toolkit itself.
Next week I'll make a quick project with the toolkit's latest version and I'll give you a feedback ASAP.
Thank you for your time.

@kacciocciacciara
Copy link
Author

Hi @Keboo
I made the test project with the same logic of my actual project.
I confirm that this solution works with 4.1.0 but doesn't with 4.2.1.
Please let me know if I did a mistake using the package.
Thank you
DemoMaterialDesignXAML.zip
.

@Keboo
Copy link
Member

Keboo commented Sep 27, 2021

Hi @kacciocciacciara thank you for the example. That is very helpful.
There was some performance caching that was introduced in 4.2.1 that fixed a different bug which is the reason for the behavior you are now seeing. The issue you are running into is because you are setting the color theme resources twice in your App.xaml.
Specifically this:

<materialDesign:BundledTheme BaseTheme="Light" PrimaryColor="Blue" SecondaryColor="Green" ColorAdjustment="{materialDesign:ColorAdjustment}"/>

And this:

<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Green.xaml" />

Both set the color theme resources. I recommend that you only use one of them (my preference is the first one). Only having one of those in the App.xaml will resolve the issue you are seeing.

@Keboo Keboo added question Old items with this tag will be automatically closed. and removed Waiting on feedback Additional information is needed. Stale items with this label may be closed. labels Sep 27, 2021
@kacciocciacciara
Copy link
Author

Hi @Keboo
I tried your solution and it works like intended.
The only "problem" now is that accessing resources like PrimaryHueMidBrush is difficult because I need to remember the exact name without the help of XAML IntelliSense. If you have a suggestion about this, I'm all ears.
Thank you very much for your assistance.

@Keboo
Copy link
Member

Keboo commented Sep 28, 2021

@kacciocciacciara Unforuently right now you sort of have to decide between the XAML intellisense of the second option I posted, and the convenience of the BundledTheme. That is something that is working on being addressed in the 4.3.0 release as part of #2435

@kacciocciacciara
Copy link
Author

@Keboo I read the issue about the color naming. Very interesting, and I feel like it's better than the actual system.
I'll close this issue, you answered all I needed to know.
Thank you again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Old items with this tag will be automatically closed.
Projects
None yet
Development

No branches or pull requests

2 participants