Jeff
Jeff

Reputation: 177

Programmatically Limiting/setting the height of a ContextMenu Sub-menu

I am programmatically creating a taskbar notify icon and Right Click ContextMenu in a C# WPF application.

A couple of the ContextMenu items have submenus whicr are populated from webservice calls. One of these is can span the entire height of the users screen, because it is over 100 entries, and you get the overflow arrows. I would like to be able to set max height to like 500.

I have been unable to figure out how to limit the size of these ContextMenu submenus programmatically. Below is the code I used to create the "Directory" submenu, which in theory can contain 0 to 1,000 entries.

Is it possible? Any help is appreciated, Thank you.

m_menu = new System.Windows.Forms.ContextMenu();

System.Windows.Forms.MenuItem newMenuItem4 = new System.Windows.Forms.MenuItem("Directory");
System.Windows.Forms.MenuItem newExistMenuItem4 = (System.Windows.Forms.MenuItem)this.m_menu.MenuItems[0]; 

if (numbers.Count > 0) 
{
    int indx = 0;
    foreach (string number in getContactDirectory() )
    {
       newMenuItem4.MenuItems.Add(indx,
       new System.Windows.Forms.MenuItem(number, new System.EventHandler(historyCall)));
       indx++;
    }
    m_menu.MenuItems.Add(menuCounter, newMenuItem4); 
    menuCounter++;
}

Upvotes: 0

Views: 1908

Answers (1)

Carbine
Carbine

Reputation: 7903

You need to familiarize yourself with Control templates and XAML.

Have a look at the blog - http://xcalibur37.wordpress.com/2013/05/09/an-enhanced-menuitem-to-limit-submenu-height/

This should answer yoour question - Best way to set a MenuItem's sub-menu height?

Upvotes: 1

Related Questions