Dark/Light mode of system tray icon in WPF

Rajib Chandra Pal 1 Reputation point

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;
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,709 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Hui Liu-MSFT 47,331 Reputation points Microsoft Vendor

    For changing the background color of the icon context menu, you could refer to the following code to use ContextMenuStrip and set ContextMenuStrip.BackColor.
    If you want to use ContextMenu, you can also try to refer to the answer here.

    The code of xaml:

            <Button Click="Button_Click" Width="100" Height="80"> click</Button>  

    The code of xaml.cs:

    using System;  
    using System.Windows;  
    using System.Windows.Forms;  
    using MessageBox = System.Windows.MessageBox;  
    namespace DarkLightofTrayIcon  
      public partial class MainWindow : Window  
        public MainWindow()  
        ContextMenuStrip menuStrip;  
        private void Button_Click(object sender, RoutedEventArgs e)  
          NotifyIcon notifyIcon = new NotifyIcon();  
          notifyIcon.Icon = new System.Drawing.Icon(@"icon.ico");  
          notifyIcon.Visible = true;  
          menuStrip = new ContextMenuStrip();  
          menuStrip.BackColor = System.Drawing.Color.Gray;  
          menuStrip.Opening+= new System.ComponentModel.CancelEventHandler(cms_Opening);  
          notifyIcon.ContextMenuStrip = menuStrip;  
        void cms_Opening(object sender, System.ComponentModel.CancelEventArgs e)  
          System.Windows.Forms.Control c = menuStrip.SourceControl as System.Windows.Forms.Control;  
          ToolStripDropDownItem tsi = menuStrip.OwnerItem as ToolStripDropDownItem;  
          if (c != null)  
            menuStrip.Items.Add("Source: " + c.GetType().ToString());  
          else if (tsi != null)  
            menuStrip.Items.Add("Source: " + tsi.GetType().ToString());  
          menuStrip.Items.Add("Apples",null, this.MenuTest1_Click);  
          menuStrip.Items.Add("Oranges", null, this.MenuTest2_Click);  
          menuStrip.Items.Add("Pears", null, this.MenuTest3_Click);  
          e.Cancel = false;  
        private void MenuTest3_Click(object sender, EventArgs e)  
        private void MenuTest2_Click(object sender, EventArgs e)  
        private void MenuTest1_Click(object sender, EventArgs e)  

    The picture of result:

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.