Menu.LevelSelectedStyles 屬性

定義

取得 MenuItemStyleCollection 物件,這個物件含有根據 Menu 控制項中的功能表項目層級,套用至選取功能表項目的樣式設定。

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

屬性值

MenuItemStyleCollection

MenuItemStyleCollection,含有根據 Menu 控制項中的功能表項目層級,套用至選取功能表項目的樣式設定。

屬性

範例

下列程式碼範例示範如何使用 LevelSelectedStyles 集合,根據控制項的層級,將樣式設定套用至控制項中的 Menu 選取功能表項目。


<%@ 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>

備註

LevelSelectedStyles使用 集合做為 和 StaticSelectedStyle 屬性的替代 DynamicSelectedStyle 專案,以控制功能表個別層級所選取功能表項目的樣式。 此集合中包含的樣式會根據其功能表層級套用至選取的功能表項目。 集合中的第一個樣式會對應至功能表第一層中所選功能表項目的樣式。 集合中的第二個樣式會對應至功能表第二層中選取功能表項目的樣式,依此類故。 這個集合最常用來產生目錄樣式導覽功能表,其中特定層級的功能表項目應該具有相同的外觀,不論它們是否具有子功能表。

注意

如果使用集合為特定層級 LevelSelectedStyles 定義樣式,這會覆寫該層級的 DynamicSelectedStyleStaticSelectedStyle 屬性。

適用於

另請參閱