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

SetWindowThemeWpf: different themes for different windows? #7

Open
Rast1234 opened this issue Jun 19, 2023 · 7 comments
Open

SetWindowThemeWpf: different themes for different windows? #7

Rast1234 opened this issue Jun 19, 2023 · 7 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@Rast1234
Copy link

Hello. I am trying to open two WPF windows (of the same type) and make them use different themes, to see them live and side by side - this way it's easier to spot style differences. Because applying/comparing themes in design time is not very convenient. I don't really care about style of the window itself, i will be happy to load dark and light style for content.

I can't find a way that, however. My observations:

  • SetWindowThemeWpf in window constructor, after InitializeComponent, does nothing visible
  • I can omit it entirely and rely only on SetCurrentProcessTheme
  • Calling SetWindowThemeWpf as it's suggested in docs, later, eg with a button click, does nothing
  • Calling SetCurrentProcessTheme anytime changes the theme for all windows
@Rast1234
Copy link
Author

Thanks for the library and write-up of how this all works! Implementing dark mode in WPF is surprisingly difficult, your approach was the only one i was able to fit into my app while understanding what it does

@Aldaviva
Copy link
Owner

Aldaviva commented Jun 19, 2023

This symptom seems to usually be caused by a missing call to SetCurrentProcessTheme. Can you try calling both SetCurrentProcessTheme (at the top of App.OnStartup) and SetWindowThemeWpf (after Window.InitializeComponent returns)?

I was able to make the WPF demo app show two MainWindow instances in one single process, and each checkbox changes its own window's title bar color independently.

image

In case it helps, here is the source and binary for the modified WPF demo app with my above changes.

@Rast1234
Copy link
Author

Yea, call SetCurrentProcessTheme in the first line of App.OnStartup, and then SetWindowThemeWpf after InitializeComponent. It works as your example: window header changes color, but content style does not. Maybe i am missing something about SkinManager?

@Rast1234
Copy link
Author

Looks like it's not possible now:

  • EffectiveCurrentProcessThemeIsDarkChanged is fired only for process theme changes
  • appResources.Add(_skinResources); is global for app and if you change its source, it gets changed for all windows

I'll try to hack a manager for window scope...

@Aldaviva
Copy link
Owner

Yeah SkinManager is currently somewhat limited because it's only aware of the process's theme, not each window's effective theme. As you said, it would need to be aware of when the effective window theme changes, and it would need to modify the window's ResourceDictionary, not the app's shared ResourceDictionary. I think I considered adding this functionality in the past, but I ran into some trouble that made it difficult or impossible, and I don't remember exactly what it was.

@Rast1234
Copy link
Author

I see that you intentionally stayed away from style management in this project, and i understand why! it must be another level of madness :) Maybe this limitation is worth mentioning in readme?

@Aldaviva
Copy link
Owner

Yeah the client area can get pretty complex, especially with controls like the WPF DataGrid. But most of all, it's subjective how these controls should look in dark mode, highly dependent on existing app styles, and best left to the developers or their chosen UI libraries (MahApps, Telerik UI, etc) about how it should look, I think.

The SkinManager is definitely a limited example implementation of how to swap resource dictionaries that I added because I realized I was copying common boilerplate between multiple projects. I like your suggestion to clarify its functionality and limitations in the readme and code documentation comments.

@Aldaviva Aldaviva self-assigned this Jun 19, 2023
@Aldaviva Aldaviva added documentation Improvements or additions to documentation enhancement New feature or request labels Jun 19, 2023
Aldaviva added a commit that referenced this issue Aug 20, 2023
…ifferent windows? [appears to work, API is neither documented nor finalized]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants