I need, for my WPF app, to detect when the DWM is turned on/off or when the system theme changes.
There is such an event in WinForms, but I can’t see any in WPF.
I need, for my WPF app, to detect when the DWM is turned on/off
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I haven’t heard of a WinForms event that fires when a WinForms window receives messages from the system, however it has its ownAh, so it’s theWndProc()method that you can override. You’re probably confusing window messages for form events.StyleChangedevent that gets invoked in WinForms windows. The rest of my answer still stands though.WPF isn’t closely tied to the Windows API either as it’s a high-level technology that invests a lot of abstraction away from the internals. For one, it draws everything in a window by itself, and doesn’t ask the system to do the drawing for it (EDIT: which is why WPF lacks such a
StyleChangedevent). That said, Windows sends messages to all windows when the DWM is toggled and when the theme changes, and you can still drill down into the low level from the WPF layer to access these messages and manipulate your WPF controls accordingly.Attach a window procedure to your WPF window’s HWND (window handle) as part of your window’s
SourceInitializedevent. In your window procedure, handle theWM_DWMCOMPOSITIONCHANGEDandWM_THEMECHANGEDwindow messages respectively.Here’s a quick example (with boilerplate code adapted from this question of mine):