Last Updated: 21 Dec 2021 10:11 by ADMIN
Michael Tissington
Created on: 21 Oct 2021 13:33
Category: NotifyIcon
Type: Bug Report
NotifyIcon: TrayContextMenu is not displayed if the application does not have a MainWindow
The TrayContextMenu is not displayed if the application does not have a MainWindow. If the menu's IsOpen property is set to true in the TrayContextMenuOpening event, however, the menu is shown as expected.
        private void NotifyIcon_TrayContextMenuOpening(object sender, CancelEventArgs e)
            if (!App.Current.MainWindow.IsLoaded)
                NotifyIcon.TrayContextMenu.IsOpen = true;
1 comment
Vladimir Stoyanov
Posted on: 21 Dec 2021 10:10


We investigated the scenario and as it turns out this behavior is related to the native WPF Popup control. The context menu of the RadNotifyIcon is displayed inside a Popup and its PlacementTarget is set to the RadNotifyIcon when the application does not have a MainWindow. The Popup delays the creation of its Window until its PlacementTarget has a PresentationSource, however this never happens when the RadNotifyIcon is not placed inside one. 

With this in mind, in order to utilize the RadNotifyIcon context menu, you can place the control inside an invisible Window element. Here is some sample code:

            var window = new Window() 
                Width = 0,
                Height = 0,
                WindowStyle = WindowStyle.None,
                ShowInTaskbar = false,
                ShowActivated = false
            var icon = new RadNotifyIcon() { GuidItem = new Guid() };

            var contextMenu = new RadContextMenu();
            contextMenu.Items.Add(new RadMenuItem() { Header = "Item 1" });
            icon.TrayContextMenu = contextMenu;

            window.Content = icon;

Of course, feel free to contact us, if you have any questions regarding the scenario. 

Vladimir Stoyanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.