From 419151604ca4755550458c9f07ff125e7b3f3038 Mon Sep 17 00:00:00 2001 From: Simon G Date: Wed, 7 Apr 2021 15:06:46 +0200 Subject: [PATCH] - allow use of separators in context menu --- Lib.NotifyIcon/Windows/NotifyIcon.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Lib.NotifyIcon/Windows/NotifyIcon.cs b/Lib.NotifyIcon/Windows/NotifyIcon.cs index 26bdb05..9a6cc75 100644 --- a/Lib.NotifyIcon/Windows/NotifyIcon.cs +++ b/Lib.NotifyIcon/Windows/NotifyIcon.cs @@ -185,14 +185,18 @@ namespace Lib.NotifyIcon.Windows uint i = 1; foreach (var item in ContextMenu.Items) { - MenuItem menuItem = (MenuItem)item; + if (item is MenuItem menuItem) + { + // Add items to the native context menu by simply reusing + // the information provided within the Avalonia ContextMenu. + WindowApi.AppendMenu(popupMenu, MenuFlags.MfString, i, (string) menuItem.Header); - // Add items to the native context menu by simply reusing - // the information provided within the Avalonia ContextMenu. - WindowApi.AppendMenu(popupMenu, MenuFlags.MfString, i, (string) menuItem.Header); + // Add the mapping so that we can find the selected item later + contextItemLookup.Add(i, menuItem); + } + else if (item is Separator) + WindowApi.AppendMenu(popupMenu, MenuFlags.MfSeparator, i, null); - // Add the mapping so that we can find the selected item later - contextItemLookup.Add(i, menuItem); i++; }