MenuItemStyleCollection クラス

定義

MenuItemStyle コントロール内の Menu オブジェクトのコレクションを表します。 このクラスは継承できません。

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 プロパティが宣言によって作成され、1 つのオブジェクトが削除され、もう 1 つが 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コレクションを格納および管理するために使用されます。 コントロールはMenu、 および プロパティのMenuItemStyleCollection基になるデータ型として クラスをLevelMenuItemStylesLevelSelectedStyles使用します。

LevelMenuItemStylesプロパティと LevelSelectedStyles プロパティは、個々のスタイル プロパティ (などStaticMenuItemStyle) の代替手段です。 これらのプロパティは、メニュー内のメニュー項目のレベルに基づいて、通常のメニュー項目と選択したメニュー項目にそれぞれ適用されます。 コレクションの最初のスタイルは、メニューの最初のレベルのメニュー項目のスタイルに対応します。 コレクション内の 2 番目のスタイルは、メニューの 2 番目のレベルのメニュー項目のスタイルに対応しています。 LevelMenuItemStylesプロパティと LevelSelectedStyles プロパティは、サブメニューがあるかどうかに関係なく、特定のレベルのメニュー項目の外観が同じであるメニューを生成するために最もよく使用されます。

クラスは 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 のすべての項目を互換性のある 1 次元の 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)

IEnumerableIQueryable に変換します。

適用対象

こちらもご覧ください