Skip to content
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

How to get a system theme with ThemeManager? #9

Closed
denik7770 opened this issue Nov 20, 2019 · 9 comments
Closed

How to get a system theme with ThemeManager? #9

denik7770 opened this issue Nov 20, 2019 · 9 comments

Comments

@denik7770
Copy link

tbsys.Text = ModernWpf.ThemeManager.GetActualTheme(this).ToString();
This does not return me an actual theme, it returns a requested theme, but if there isno requested theme, then it returns default.

@denik7770
Copy link
Author

denik7770 commented Nov 20, 2019

sssss
As you see, a theme is not actually light.

@Kinnara
Copy link
Owner

Kinnara commented Nov 21, 2019

In theory, your code should work and GetActualTheme should always return either Light or Dark but never Default, otherwise there is a bug. Anyway, what it returns doesn't matter much unless you're using more advanced features like defining/overriding theme resources at the element level.

Without seeing the code it can be hard to tell what exactly went wrong in your case. One issue I see is that both ModernWPF and FluentWPF are trying to set the window style (through attached property) and only one will take effect. For the moment I believe using the FluentWPF style would be simpler. The resources in App.xaml also need to be set up in a certain way to get the two libraries work together without conflicts. I made a sample app available here to demonstrate the setup.

image

@denik7770
Copy link
Author

Thank you reaally much for your answer and support!!😊😊

@ashelleyPurdue
Copy link

Slightly off topic, but what would be the purpose behind using both FluentWPF and ModernWpf? I thought ModernWpf was, more or less, a replacement for FluentWPF.

Is it so your app can make use of the acrylic effect?

@denik7770
Copy link
Author

I think, that to make an acrylic effect, the best way is by using FluentWPF.

@denik7770
Copy link
Author

In theory, your code should work and GetActualTheme should always return either Light or Dark but never Default, otherwise there is a bug. Anyway, what it returns doesn't matter much unless you're using more advanced features like defining/overriding theme resources at the element level.

Without seeing the code it can be hard to tell what exactly went wrong in your case. One issue I see is that both ModernWPF and FluentWPF are trying to set the window style (through attached property) and only one will take effect. For the moment I believe using the FluentWPF style would be simpler. The resources in App.xaml also need to be set up in a certain way to get the two libraries work together without conflicts. I made a sample app available here to demonstrate the setup.

image

I'm still getting this issue, but at least, they do not conflict with themes.
Untitleaad

@Kinnara
Copy link
Owner

Kinnara commented Nov 22, 2019

Ah, now I see you want the app to use the Windows theme mode. Simply adding a proper app manifest should enable that. This commit 84f4069 shows how to do that. Basically you add an app manifest to your project and uncomment the Windows 10 line.

If your app still doesn't pick up the Windows theme (don't forget to remove any RequestedTheme) I also made some changes that should make system theme handling more robust. It's not published on NuGet yet but you can clone the latest code and try the FluentWPF sample.

image

@ShankarBUS
Copy link
Contributor

Hey @Kinnara, Since the requirement for app.manifest is now optional, apps will now follows system themes without any additional requirements.

The OP's problem was, they couldn't fetch system theme because they didn't have the manifest and didn't know it was required.

Can this issue be closed now?

@Kinnara
Copy link
Owner

Kinnara commented Aug 4, 2020

Yes, I believe so. Thanks for the reminder.

@Kinnara Kinnara closed this as completed Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants