WPF 捕获系统主题改变(WPF WndProc)
int msg, IntPtr lParam, EventArgs e){IntPtr hwnd;if ((hwnd = new WindowInteropHelper(sender as Window).Handle) == IntPtr.Zero)throw new InvalidOperationException("Could not get window handle.");HwndSource.FromHwnd(hwnd).AddHook(WndProc);}const int WM_DWMCOLORIZATIONCOLORCHANGED = 0x320;// see "https://stackoverflow.com/questions/13660976/get-the-active-color-of-windows-8-automatic-color-theme"IntPtr WndProc(IntPtr hwnd, IntPtr wParam, ref bool handled){switch (msg){case WM_DWMCOLORIZATIONCOLORCHANGED:/** Update gradient brushes with new color information from* NativeMethods.DwmGetColorizationParams() or the registry.*/return IntPtr.Zero;default:return IntPtr.Zero;}} 这个也可以捕获系统颜色主题改变 也是WM_DWMCOLORIZATIONCOLORCHANGED , Language Version: C# 8.0 WPF 捕获系统主题改变 通过System.Windows.Interop using System.Windows.Interop;// this is Window 可以写在构造方法里this.SourceInitialized += Theme.ThemeManager.Window_SourceInitialized;// see "https://stackoverflow.com/questions/13660976/get-the-active-color-of-windows-8-automatic-color-theme"void Window_SourceInitialized(object sender,。
- 上一篇:WPF 动态主题切换与窗口闪烁解决方案
- 下一篇:检测WPF中的系统主题更改
评论列表