I’m creating an app in WPF.
I included a Systray icon using “System.Windows.Forms.NotifyIcon”
the code looks like:
// Create WinForm notify icon
m_NotifyIcon = new System.Windows.Forms.NotifyIcon();
m_NotifyIcon.Icon = Properties.Resources.rocket;
m_NotifyIcon.Visible = true;
// Default Balloon title
m_NotifyIcon.BalloonTipTitle = "Greatest App ever";
m_NotifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu();
// Append default menu items
List<MenuItem> itemList = new List<MenuItem>();
itemList.Insert(0, new MenuItem("Exit", OnExit_Click));
itemList.Insert(0, new MenuItem("-"));
itemList.Insert(0, new MenuItem("Refresh", RefreshConsoleList));
itemList.Insert(0, new MenuItem("Filter: \"" + (String.IsNullOrEmpty(m_Filter) ? "NONE" : m_Filter) + "\"", ChangeFilter_Click));
itemList.Insert(0, new MenuItem("-"));
m_NotifyIcon.ContextMenu.MenuItems.AddRange(itemList.ToArray());
the result looks like this:
In the case of the refresh, my application will get a lot of entries, then append these entries in the ContextMenu, the menu will looks like this:
As you can see, there is too many MenuItem and because of the overflow, 2 arrows will be displayed (Top and Bottom of the ContextMenu)
Now if the user wants to Exit the application, he have to scroll down, then click on Exit.
If the list is really big, it can annoy the user.
To avoid this, I want to display the ContextMenu already scrolled to the bottom when it pop up (the first MenuItem is visible)
But I didn’t find any event or control to use to Scroll Down programmatically the ContextMenu.
Is it possible to do?
Regards
Yves Desgraupes
PS: I was unable to directly post the Images because of my reputation (it’s my first post), and post more than 2 links.
the third exemple is here:
yves.desgraupes.free.fr/shared/ContextMenu_OverflowScroll.png
What you could do is use a WPF implementation of the NotifyIcon.
Then you could have a WPF menu, and have more control over how you implement the behaviour you want in the menu.
So you could define a Template for the ContextMenu and get access to the ScrollViewer within the ContextMenu template and then call ScrollToEnd() on it.
Here’s an example that shows how to create a WPF context menu that when it starts up is scrolled to the end. You can use this in your WPF NotifyIcon. Right click on the Button to see the contextmenu.
Note I’ve provided it as a starting point….you may be able to improve the code..reduce some repetitions…but it works….e.g…to get around a glitch when the menu is first displayed it doesn’t scroll to the end I had to trap the SizeChanged event.
On a side note….you might want to limit the height of the ContextMenu…by setting MaxHeight…demo here.