MenuItemStyleCollection 類別

定義

代表 Menu 控制項中 MenuItemStyle 物件的集合。 此類別無法獲得繼承。

public ref class MenuItemStyleCollection sealed : System::Web::UI::StateManagedCollection
public sealed class MenuItemStyleCollection : System.Web.UI.StateManagedCollection
type MenuItemStyleCollection = class
    inherit StateManagedCollection
Public NotInheritable Class MenuItemStyleCollection
Inherits StateManagedCollection
繼承
MenuItemStyleCollection

範例

下列程式碼範例示範如何使用 MenuItemStyleCollection 類別,根據功能表項目的層級,指定控制項中 Menu 功能表項目的樣式設定。 在此範例中 LevelMenuItemStyles ,屬性會以宣告方式建立,並移除一個 MenuItemStyle 物件,另一個物件會新增至 MenuItemStyleCollection 物件。


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void Page_Load(Object sender, EventArgs e)
  {

    if (!IsPostBack)
    {

      // Use the Add and RemoveAt methods to programmatically 
      // remove the third level menu item style and replace 
      // it with a new style, in this case replacing the green background
        // and yellow text with the blue background and white text. 

        MenuItemStyle newStyle = new MenuItemStyle();
        newStyle.BackColor = System.Drawing.Color.Blue;
        newStyle.ForeColor = System.Drawing.Color.White;

        // Remove the last of the three menu item styles. Note that
        // since the collection has a zero-based index, the third
        // entry has an index value of 2.
        MainMenuID.LevelMenuItemStyles.RemoveAt(2);
        MainMenuID.LevelMenuItemStyles.Add(newStyle);

    }

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItemStyleCollection Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItemStyleCollection Example</h3>
         <!--Add MenuItemStyle objects to the MenuItemStyleCollection -->
         <!--using LevelMenuItemStyles.  -->
         <!--Note that each menu item style represents a level in the menu -->

      <asp:Menu id="MainMenuID"
       Font-Names= "Arial"
        ForeColor="Blue"
        runat="server">
         
         <LevelMenuItemStyles>
         <asp:MenuItemStyle BackColor="Azure" 
             Font-Italic="true"
             Font-Names="Arial"
             ForeColor="Black" />
         
           <asp:MenuItemStyle BackColor="Black" 
             Font-Italic="false"
             Font-Names="Arial"
             ForeColor="White" />
             
         <asp:MenuItemStyle BackColor="Green" 
             Font-Italic="true"
             Font-Names="Arial"
             ForeColor="Yellow" />
       
         </LevelMenuItemStyles>

        <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">
<script runat="server">

Sub Page_Load(ByVal sender As [Object], ByVal e As EventArgs) 
    
    If Not IsPostBack Then
        
        ' Use the Add and RemoveAt methods to programmatically 
        ' remove the third level menu item style and replace 
        ' it with a new style, in this case replacing the green background
        ' and yellow text with the blue background and white text. 
        Dim newStyle As New MenuItemStyle()
        newStyle.BackColor = System.Drawing.Color.Blue
        newStyle.ForeColor = System.Drawing.Color.White
        
        ' Remove the last of the three menu item styles. Note that
        ' since the collection has a zero-based index, the third
        ' entry has an index value of 2.
        MainMenuID.LevelMenuItemStyles.RemoveAt(2)
        MainMenuID.LevelMenuItemStyles.Add(newStyle)
    End If
 
End Sub 'Page_Load
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItemStyleCollection Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItemStyleCollection Example</h3>
         <!--Add MenuItemStyle objects to the MenuItemStyleCollection -->
         <!--using LevelMenuItemStyles.   -->
         <!--Note that each menu item style represents a level in the menu -->

      <asp:Menu id="MainMenuID"
       Font-Names= "Arial"
        ForeColor="Blue"
        runat="server">
         
         <LevelMenuItemStyles>
         <asp:MenuItemStyle BackColor="Azure" 
             Font-Italic="true"
             Font-Names="Arial"
             ForeColor="Black" />
         
           <asp:MenuItemStyle BackColor="Black" 
             Font-Italic="false"
             Font-Names="Arial"
             ForeColor="White" />
             
         <asp:MenuItemStyle BackColor="Green" 
             Font-Italic="true"
             Font-Names="Arial"
             ForeColor="Yellow" />
       
         </LevelMenuItemStyles>

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

備註

類別 MenuItemStyleCollection 可用來儲存和管理 控制項中的 Menu 物件集合 MenuItemStyle 。 控制項 MenuMenuItemStyleCollection 使用 類別做為 和 LevelSelectedStyles 屬性的基礎資料類型 LevelMenuItemStyles

LevelMenuItemStylesLevelSelectedStyles 屬性是個別樣式屬性的替代方案, (例如 StaticMenuItemStyle) 。 這些屬性會分別根據功能表項目的功能表項目層級套用至一般功能表項目和選取的功能表項目。 集合中的第一個樣式會對應至功能表第一層的功能表項目樣式。 集合中的第二個樣式會對應至功能表第二層的功能表項目樣式,依此類故。 LevelMenuItemStylesLevelSelectedStyles 屬性最常用來產生功能表,其中特定層級的功能表項目具有相同的外觀,不論它們是否具有子功能表。

類別 MenuItemStyleCollection 會繼承 StateManagedCollection 類別的大部分成員。 如需繼承成員的詳細資訊,請參閱 StateManagedCollection

屬性

Count

取得 StateManagedCollection 集合中所包含的項目數。

(繼承來源 StateManagedCollection)
Item[Int32]

取得集合中位於指定索引處的 MenuItemStyle 物件。

方法

Add(MenuItemStyle)

將指定的 MenuItemStyle 物件附加至目前集合的結尾。

Clear()

將所有項目從 StateManagedCollection 集合中移除。

(繼承來源 StateManagedCollection)
Contains(MenuItemStyle)

判斷指定的 MenuItemStyle 物件是否在集合中。

CopyTo(Array, Int32)

從特定的陣列索引開始,將 StateManagedCollection 集合的項目複製到陣列。

(繼承來源 StateManagedCollection)
CopyTo(MenuItemStyle[], Int32)

從目標陣列中的指定索引開始,從 MenuItemStyleCollection 物件中,將所有項目複製至相容的一維陣列 MenuItemStyle 物件。

CreateKnownType(Int32)

在衍生類別中覆寫時,建立實作 IStateManager 之類別的執行個體。 根據 GetKnownTypes() 方法所傳回之集合指定的成員,建立物件的類型。

(繼承來源 StateManagedCollection)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetEnumerator()

傳回逐一查看 StateManagedCollection 集合的列舉值。

(繼承來源 StateManagedCollection)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetKnownTypes()

在衍生類別中覆寫時,取得 StateManagedCollection 集合可以包含之 IStateManager 類型的陣列。

(繼承來源 StateManagedCollection)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IndexOf(MenuItemStyle)

判斷集合中指定之 MenuItemStyle 物件的索引。

Insert(Int32, MenuItemStyle)

將指定的 MenuItemStyle 物件插入至集合中指定的索引位置。

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
OnClear()

在衍生類別中覆寫時,在 Clear() 方法移除集合的所有項目之前,執行額外工作。

(繼承來源 StateManagedCollection)
OnClearComplete()

在衍生類別中覆寫時,在 Clear() 方法完成移除集合的所有項目之後,執行額外工作。

(繼承來源 StateManagedCollection)
OnInsert(Int32, Object)

在衍生類別中覆寫時,在 IList.Insert(Int32, Object)IList.Add(Object) 方法將項目加入集合之前,執行額外工作。

(繼承來源 StateManagedCollection)
OnInsertComplete(Int32, Object)

在衍生類別中覆寫時,在 IList.Insert(Int32, Object)IList.Add(Object) 方法將項目加入集合之後,執行額外工作。

(繼承來源 StateManagedCollection)
OnRemove(Int32, Object)

在衍生類別中覆寫時,在 IList.Remove(Object)IList.RemoveAt(Int32) 方法從集合中移除指定的項目之前,執行額外工作。

(繼承來源 StateManagedCollection)
OnRemoveComplete(Int32, Object)

在衍生類別中覆寫時,在 IList.Remove(Object)IList.RemoveAt(Int32) 方法從集合中移除指定的項目之後,執行額外工作。

(繼承來源 StateManagedCollection)
OnValidate(Object)

在衍生類別中覆寫時,驗證 StateManagedCollection 集合的項目。

(繼承來源 StateManagedCollection)
Remove(MenuItemStyle)

從集合中移除指定的 MenuItemStyle 物件。

RemoveAt(Int32)

從集合中移除指定索引位置的 MenuItemStyle 物件。

SetDirty()

強制整個 StateManagedCollection 集合序列化至檢視狀態。

(繼承來源 StateManagedCollection)
SetDirtyObject(Object)

在衍生類別中覆寫時,指示集合中所包含的 object,將其完整狀態 (而不只是變更資訊) 記錄至檢視狀態。

(繼承來源 StateManagedCollection)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

ICollection.Count

取得 StateManagedCollection 集合中所包含的項目數。

(繼承來源 StateManagedCollection)
ICollection.IsSynchronized

取得值,表示 StateManagedCollection 集合是否為同步 (安全執行緒)。 在所有情況下,這個方法都會傳回 false

(繼承來源 StateManagedCollection)
ICollection.SyncRoot

取得物件,可用來同步處理對 StateManagedCollection 集合的存取。 在所有情況下,這個方法都會傳回 null

(繼承來源 StateManagedCollection)
IEnumerable.GetEnumerator()

傳回逐一查看 StateManagedCollection 集合的列舉值。

(繼承來源 StateManagedCollection)
IList.Add(Object)

將項目加入 StateManagedCollection 集合。

(繼承來源 StateManagedCollection)
IList.Clear()

將所有項目從 StateManagedCollection 集合中移除。

(繼承來源 StateManagedCollection)
IList.Contains(Object)

判斷 StateManagedCollection 集合是否包含特定值。

(繼承來源 StateManagedCollection)
IList.IndexOf(Object)

判斷 StateManagedCollection 集合中指定之項目的索引。

(繼承來源 StateManagedCollection)
IList.Insert(Int32, Object)

將項目插入位於指定索引處的 StateManagedCollection 集合中。

(繼承來源 StateManagedCollection)
IList.IsFixedSize

取得值,表示 StateManagedCollection 集合是否具有固定大小。 在所有情況下,這個方法都會傳回 false

(繼承來源 StateManagedCollection)
IList.IsReadOnly

取得值,表示 StateManagedCollection 集合是否為唯讀。

(繼承來源 StateManagedCollection)
IList.Item[Int32]

取得指定索引處的 IStateManager 項目。

(繼承來源 StateManagedCollection)
IList.Remove(Object)

StateManagedCollection 集合中移除指定物件的第一個符合項目。

(繼承來源 StateManagedCollection)
IList.RemoveAt(Int32)

移除指定索引處的 IStateManager 項目。

(繼承來源 StateManagedCollection)
IStateManager.IsTrackingViewState

取得值,表示 StateManagedCollection 集合是否正在儲存變更至檢視狀態。

(繼承來源 StateManagedCollection)
IStateManager.LoadViewState(Object)

還原先前儲存之 StateManagedCollection 集合和內含 IStateManager 項目的檢視狀態。

(繼承來源 StateManagedCollection)
IStateManager.SaveViewState()

儲存自頁面回傳至伺服器以來 StateManagedCollection 集合和每個內含 IStateManager 物件的變更。

(繼承來源 StateManagedCollection)
IStateManager.TrackViewState()

使得 StateManagedCollection 集合和每個內含 IStateManager 物件追蹤其檢視狀態的變更,以便跨相同頁面要求保存這些變更。

(繼承來源 StateManagedCollection)

擴充方法

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。

AsParallel(IEnumerable)

啟用查詢的平行化作業。

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryable

適用於

另請參閱