简体   繁体   中英

Dynamically add MenuItems to a MenuItem and statically view them

I want to dynamically add some MenuItems to a MenuItem.ChildItems , but I want to see them statically. In other words, I just want to let the MenuItems always be visible and not only when I hover over it.

for ( int i = 0; i < lista.count; i++)
{
    MenuItem nuovo = new MenuItem();

    nuovo.NavigateUrl = "www.google.com"
    nuovo.Text = "prova" + i;

    attualeItem.ChildItems.Add(nuovo);
}

You need to modify 1 to 2 properties of your Menu control:

StaticDisplayLevels : 2 - The number of levels displayed in the static part of the menu .

  • 2 if you have only Parents and Children. It will increase depending on how many levels deep is your menu.

StaticSubMenuIndent (Optional) : The indentation between a static menu item and its static sub-menu items .

  • So you will set this to 20px or 30px, or whatever distance you want them apart.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM