Edytuj

Udostępnij za pośrednictwem


Menu.LevelMenuItemStyles Property

Definition

Gets a MenuItemStyleCollection object that contains the style settings that are applied to menu items based on their level in a Menu control.

public:
 property System::Web::UI::WebControls::MenuItemStyleCollection ^ LevelMenuItemStyles { System::Web::UI::WebControls::MenuItemStyleCollection ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public System.Web.UI.WebControls.MenuItemStyleCollection LevelMenuItemStyles { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.LevelMenuItemStyles : System.Web.UI.WebControls.MenuItemStyleCollection
Public ReadOnly Property LevelMenuItemStyles As MenuItemStyleCollection

Property Value

A MenuItemStyleCollection that contains the style settings that are applied to menu items based on their level in a Menu control.

Attributes

Examples

The following code example demonstrates how to use the LevelMenuItemStyles collection to apply style settings to the menu items in a Menu control based on their level.


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>Menu LevelMenuItemStyles and LevelSelectedStyles Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>Menu LevelMenuItemStyles and LevelSelectedStyles Example</h3>

      <asp:menu id="NavigationMenu"
        staticdisplaylevels="2"
        staticsubmenuindent="10" 
        orientation="Vertical"
        target="_blank"  
        runat="server">
        
        <levelmenuitemstyles>
          <asp:menuitemstyle BackColor="LightSteelBlue"
            forecolor="Black"/>
          <asp:menuitemstyle BackColor="SkyBlue"
            forecolor="Black"/>
          <asp:menuitemstyle BackColor="LightSkyBlue"
            forecolor="Black"/>            
        </levelmenuitemstyles>
        <levelselectedstyles>
          <asp:menuitemstyle BackColor="Cyan"
           forecolor="Gray"/>
          <asp:menuitemstyle BackColor="LightCyan"
           forecolor="Gray"/>
          <asp:menuitemstyle BackColor="PaleTurquoise"
           forecolor="Gray"/>            
        </levelselectedstyles>    
      
        <items>
          <asp:menuitem text="Home"
            tooltip="Home">
            <asp:menuitem text="Music"
              tooltip="Music">
              <asp:menuitem text="Classical"
                tooltip="Classical"/>
              <asp:menuitem text="Rock"
                tooltip="Rock"/>
              <asp:menuitem text="Jazz"
                tooltip="Jazz"/>
            </asp:menuitem>
            <asp:menuitem text="Movies"
              tooltip="Movies">
              <asp:menuitem text="Action"
                tooltip="Action"/>
              <asp:menuitem text="Drama"
                tooltip="Drama"/>
              <asp:menuitem text="Musical"
                tooltip="Musical"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>
      
      </asp:menu>

    </form>
  </body>
</html>

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>Menu LevelMenuItemStyles and LevelSelectedStyles Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>Menu LevelMenuItemStyles and LevelSelectedStyles Example</h3>

      <asp:menu id="NavigationMenu"
        staticdisplaylevels="2"
        staticsubmenuindent="10" 
        orientation="Vertical"
        target="_blank"  
        runat="server">
        
        <levelmenuitemstyles>
          <asp:menuitemstyle BackColor="LightSteelBlue"
            forecolor="Black"/>
          <asp:menuitemstyle BackColor="SkyBlue"
            forecolor="Black"/>
          <asp:menuitemstyle BackColor="LightSkyBlue"
            forecolor="Black"/>            
        </levelmenuitemstyles>
        <levelselectedstyles>
          <asp:menuitemstyle BackColor="Cyan"
           forecolor="Gray"/>
          <asp:menuitemstyle BackColor="LightCyan"
           forecolor="Gray"/>
          <asp:menuitemstyle BackColor="PaleTurquoise"
           forecolor="Gray"/>            
        </levelselectedstyles>    
      
        <items>
          <asp:menuitem text="Home"
            tooltip="Home">
            <asp:menuitem text="Music"
              tooltip="Music">
              <asp:menuitem text="Classical"
                tooltip="Classical"/>
              <asp:menuitem text="Rock"
                tooltip="Rock"/>
              <asp:menuitem text="Jazz"
                tooltip="Jazz"/>
            </asp:menuitem>
            <asp:menuitem text="Movies"
              tooltip="Movies">
              <asp:menuitem text="Action"
                tooltip="Action"/>
              <asp:menuitem text="Drama"
                tooltip="Drama"/>
              <asp:menuitem text="Musical"
                tooltip="Musical"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>
      
      </asp:menu>

    </form>
  </body>
</html>

Remarks

Use the LevelMenuItemStyles collection as an alternative to the individual style properties (such as DynamicMenuItemStyle) to control the style of menu items at the individual levels of the menu. The styles contained in this collection are applied to the menu items based on their menu level. The first style in the collection corresponds to the style of menu items in the first level of the menu. The second style in the collection corresponds to the style of menu items in the second level of the menu, and so on. This collection is most often used to generate table of contents-style navigation menus where menu items at a certain level should have the same appearance, regardless of whether they have submenus.

Note

If a style is defined for a certain level using the LevelMenuItemStyles collection, this overrides any menu item style settings for the menu items at that level.

Applies to

See also