I am using notify icon in my WPF app. When I click this icon, always there is a white background of context menu but I want to change this for Dark mode. But how to apply Dark & Light mode in notify icon?
_notifyIcon = new Forms.NotifyIcon();
_notifyIcon.Icon = MySystray.Resources.Systray_icon;
_notifyIcon.Text = APP_NAME;
If you want to use WPF context menu with windows form’s NotifyIcon then you may need to invoke Mouse Hook to track down the mouse pointer for hiding the Context menu if you click outside of the menu area. Otherwise, this context menu will never hide. This is another context.
I have also faced the same problem. By doing, long R&D I have found that there is a only way to resolve this problem to override the Renderer of the context menu. There are different types of Renderer exist out there. I have used ToolStripProfessionalRenderer. For getting the full benefit, I have also inherited ProfessionalColorTable. Finally, I have used this customized render as My Context menus render panel. Here below is Step.
Firstly, create MenuColorTable by Inheriting ProfessionalColorTable.
Create necessary utility class:
Now override ToolStripProfessionalRenderer with customized MenuColorTable.
Now it's time to create your custom own StripMenu by inheriting ContextMenuStrip. Assign your custom MenuRenderer as ContextMenus’s Render by overriding OnHandleCreated
Now it's time to create your custom own StripMenu by inheriting ContextMenuStrip. Assign your custom MenuRenderer as ContextMenus’s Render by overriding OnHandleCreated
Finally, create different types of the menu's for a different theme and assign them as NotiIcon's ContextMenuStrip based on windows' current theme.
By the way, you can detect system theme changed event from wpf through WMI query watcher. Here you find my answers for runtime theme change detection from wpf.
Do not forget to invalid the NotifyIcon after reassigning the new context menu based on windows' current theme.