private void NotifyIcon_TrayContextMenuOpening(object sender, CancelEventArgs e)
{
BuildContextMenu(NotifyIcon.TrayContextMenu);
if (!App.Current.MainWindow.IsLoaded)
NotifyIcon.TrayContextMenu.IsOpen = true;
}
Hello,
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;
icon.AddIcon();
window.Content = icon;
window.Show();
Of course, feel free to contact us, if you have any questions regarding the scenario.
Regards,
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.