Menu.StaticSelectedStyle Egenskap

Definition

Hämtar en referens till objektet MenuItemStyle som gör att du kan ange utseendet på menyalternativet som valts av användaren i en statisk meny.

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

Egenskapsvärde

En referens till MenuItemStyle det som representerar formatet för det valda menyalternativet i en statisk meny.

Attribut

Exempel

I följande kodexempel visas hur du använder StaticSelectedStyle egenskapen för att ange en ljusblå bakgrundsfärg för det valda statiska menyalternativet.


<%@ 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 StaticSelectedStyle Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>Menu StaticSelectedStyle Example</h3>
    
      <asp:menu id="NavigationMenu"
        staticdisplaylevels="2"
        staticsubmenuindent="10" 
        orientation="Vertical"
        runat="server">
        
        <staticselectedstyle backcolor="LightBlue"
          borderstyle="Solid"
          bordercolor="Black"
          borderwidth="1"/>
      
        <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 StaticSelectedStyle Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>Menu StaticSelectedStyle Example</h3>
    
      <asp:menu id="NavigationMenu"
        staticdisplaylevels="2"
        staticsubmenuindent="10" 
        orientation="Vertical"
        runat="server">
        
        <staticselectedstyle backcolor="LightBlue"
          borderstyle="Solid"
          bordercolor="Black"
          borderwidth="1"/>
      
        <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>

Kommentarer

Använd egenskapen StaticSelectedStyle för att styra utseendet på menyalternativet som användaren har valt i en statisk meny. Den här egenskapen är skrivskyddad. Du kan dock ange egenskaperna för det objekt som MenuItemStyle returneras. Egenskaperna kan anges deklarativt i formuläret Property-Subproperty, där Subproperty är en egenskap MenuItemStyle för objektet (till exempel StaticSelectedStyle-ForeColor). Egenskaperna kan också anges programmatiskt i formuläret Property.Subproperty (till exempel StaticSelectedStyle.ForeColor).

Formategenskaper för ett statiskt menyalternativ tillämpas i följande ordning:

  1. StaticMenuStyle.

  2. StaticMenuItemStyle. Om samlingen eller LevelMenuItemStyles samlingen har definierats tillämpas den LevelSubMenuStyles just nu, vilket åsidosätter de andra egenskaperna för menyalternativsformat.

  3. StaticSelectedStyle. Om samlingen har definierats tillämpas den LevelSelectedStyles just nu, vilket åsidosätter de andra egenskaperna för menyalternativsformat.

  4. StaticHoverStyle.

Important

Icke-bakåtkompatibel ändring nedan.

Innan .NET Framework 4.0, när du definierar en <asp:Menu>-kontroll i .aspx-filen, kan användarna ange egenskapen StaticSelectedStyle-CssClass för att ange CSS-klassen för det valda kontrollobjektet. Användaren kan till exempel ha en menykontroll enligt nedan:

<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal" 
    StaticMenuItemStyle-CssClass="MenuItem"
    StaticSelectedStyle-CssClass="MenuItem_selected"
    OnMenuItemClick="Menu1_MenuItemClick" Style="margin-bottom: 0px" EnableTheming="True" ClientIDMode="Static">
    <Items>
        <asp:MenuItem Text="item_0" Value="0" Selected="True"></asp:MenuItem>
        <asp:MenuItem Text="itme_1" Value="1"></asp:MenuItem>
    </Items>
</asp:Menu>

Och menykontrollen återges som:

<div id="Menu1" style="margin-bottom: 0px">
    <ul class="level1">
        <li><a class="level1 MenuItem MenuItem_selected " href="#" onclick="__doPostBack(&#39;Menu1&#39;,&#39;0&#39;)">item_0</a></li>
        <li><a class="level1 MenuItem" href="#" onclick="__doPostBack(&#39;Menu1&#39;,&#39;1&#39;)">itme_1</a></li>
    </ul>
</div>

Men i .NET Framework 4.0 och senare är det valda menyalternativet inställt på css-klassen selected alltid i stället för den klass som anges av StaticSelectedStyle-CssClass. Därför återges ovanstående ASP.NET kod i stället som:

<div id="Menu1" style="margin-bottom: 0px">
    <ul class="level1">
        <li><a class="level1 MenuItem selected " href="#" onclick="__doPostBack(&#39;Menu1&#39;,&#39;0&#39;)">item_0</a></li>
        <li><a class="level1 MenuItem" href="#" onclick="__doPostBack(&#39;Menu1&#39;,&#39;1&#39;)">itme_1</a></li>
    </ul>
</div>

Gäller för

Se även