.NET Framework Class Library MenuItemStyleCollection Class Represents a collection of MenuItemStyle objects in a Menu control. This class cannot be inherited.

Inheritance Hierarchy
Namespace:
System.Web.UI.WebControls
Assembly:
System.Web (in System.Web.dll)

Syntax
Public NotInheritable Class MenuItemStyleCollection _
Inherits StateManagedCollection
public sealed class MenuItemStyleCollection : StateManagedCollection
public ref class MenuItemStyleCollection sealed : public StateManagedCollection
[<Sealed>]
type MenuItemStyleCollection =
class
inherit StateManagedCollection
end
The MenuItemStyleCollection type exposes the following members.

Properties

Methods
|
| Name | Description |
|---|
.gif) | Add | Appends the specified MenuItemStyle object to the end of the current collection. | .gif) | Clear | Removes all items from the StateManagedCollection collection. (Inherited from StateManagedCollection.) | .gif) | Contains | Determines whether the specified MenuItemStyle object is in the collection. | .gif) | CopyTo(Array, Int32) | Copies the elements of the StateManagedCollection collection to an array, starting at a particular array index. (Inherited from StateManagedCollection.) | .gif) | CopyTo(array<MenuItemStyle>[]()[], Int32) | Copies all the items from the MenuItemStyleCollection object to a compatible one-dimensional array of MenuItemStyle objects, starting at the specified index in the target array. | .gif) | CreateKnownType | When overridden in a derived class, creates an instance of a class that implements IStateManager. The type of object created is based on the specified member of the collection returned by the GetKnownTypes method. (Inherited from StateManagedCollection.) | .gif) | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | .gif) | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | .gif) | GetEnumerator | Returns an iterator that iterates through the StateManagedCollection collection. (Inherited from StateManagedCollection.) | .gif) | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | .gif) | GetKnownTypes | When overridden in a derived class, gets an array of IStateManager types that the StateManagedCollection collection can contain. (Inherited from StateManagedCollection.) | .gif) | GetType | Gets the Type of the current instance. (Inherited from Object.) | .gif) | IndexOf | Determines the index of the specified MenuItemStyle object in the collection. | .gif) | Insert | Inserts the specified MenuItemStyle object into the collection at the specified index location. | .gif) | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | .gif) | OnClear | When overridden in a derived class, performs additional work before the Clear method removes all items from the collection. (Inherited from StateManagedCollection.) | .gif) | OnClearComplete | When overridden in a derived class, performs additional work after the Clear method finishes removing all items from the collection. (Inherited from StateManagedCollection.) | .gif) | OnInsert | When overridden in a derived class, performs additional work before the Insert(Int32, Object) or Add(Object) method adds an item to the collection. (Inherited from StateManagedCollection.) | .gif) | OnInsertComplete | When overridden in a derived class, performs additional work after the Insert(Int32, Object) or Add(Object) method adds an item to the collection. (Inherited from StateManagedCollection.) | .gif) | OnRemove | When overridden in a derived class, performs additional work before the Remove(Object) or RemoveAt(Int32) method removes the specified item from the collection. (Inherited from StateManagedCollection.) | .gif) | OnRemoveComplete | When overridden in a derived class, performs additional work after the Remove(Object) or RemoveAt(Int32) method removes the specified item from the collection. (Inherited from StateManagedCollection.) | .gif) | OnValidate | When overridden in a derived class, validates an element of the StateManagedCollection collection. (Inherited from StateManagedCollection.) | .gif) | Remove | Removes the specified MenuItemStyle object from the collection. | .gif) | RemoveAt | Removes the MenuItemStyle object at the specified index location from the collection. | .gif) | SetDirty | Forces the entire StateManagedCollection collection to be serialized into view state. (Inherited from StateManagedCollection.) | .gif) | SetDirtyObject | When overridden in a derived class, instructs an object contained by the collection to record its entire state to view state, rather than recording only change information. (Inherited from StateManagedCollection.) | .gif) | ToString | Returns a string that represents the current object. (Inherited from Object.) | Top

Explicit Interface Implementations

Remarks
The MenuItemStyleCollection class is used to store and manage a collection of MenuItemStyle objects in a Menu control. The Menu control uses the MenuItemStyleCollection class as the underlying data type of the LevelMenuItemStyles and LevelSelectedStyles properties. The LevelMenuItemStyles and LevelSelectedStyles properties are an alternative to the individual style properties (such as StaticMenuItemStyle). These properties are applied to regular menu items and the selected menu item, respectively, based on the menu item's level in the menu. The first style in the collection corresponds to the menu item style for the first level of the menu. The second style in the collection corresponds to the menu item style for the second level of the menu, and so on. The LevelMenuItemStyles and LevelSelectedStyles properties are most often used to generate menus where menu items at a certain level have the same appearance, regardless of whether they have submenus. The MenuItemStyleCollection class inherits most of its members from the StateManagedCollection class. For more information on the inherited members, see StateManagedCollection.

Examples
The following code example demonstrates how to use the MenuItemStyleCollection class to specify the style settings for the menu items in a Menu control based on the menu item's level. In this example, the LevelMenuItemStyles property is created declaratively, and one MenuItemStyle object is removed and another added to the MenuItemStyleCollection object.
<%@ 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 >
<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="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 >
<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>

Version Information
.NET FrameworkSupported in: 4, 3.5, 3.0, 2.0

Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Thread Safety
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also
|
Bibliothèque de classes .NET Framework MenuItemStyleCollection, classe Représente une collection d'objets MenuItemStyle dans un contrôle Menu. Cette classe ne peut pas être héritée.

Hiérarchie d'héritage
Espace de noms :
System.Web.UI.WebControls
Assembly :
System.Web (dans System.Web.dll)

Syntaxe
Public NotInheritable Class MenuItemStyleCollection _
Inherits StateManagedCollection
public sealed class MenuItemStyleCollection : StateManagedCollection
public ref class MenuItemStyleCollection sealed : public StateManagedCollection
[<Sealed>]
type MenuItemStyleCollection =
class
inherit StateManagedCollection
end
Le type MenuItemStyleCollection expose les membres suivants.

Propriétés

Méthodes
|
| Nom | Description |
|---|
.gif) | Add | Ajoute l'objet MenuItemStyle spécifié à la fin de la collection en cours. | .gif) | Clear | Supprime tous les éléments de la collection StateManagedCollection. (Hérité de StateManagedCollection.) | .gif) | Contains | Détermine si l'objet MenuItemStyle spécifié se trouve dans la collection. | .gif) | CopyTo(Array, Int32) | Copie les éléments de la collection StateManagedCollection dans un tableau, en commençant au niveau d'un index de tableau particulier. (Hérité de StateManagedCollection.) | .gif) | CopyTo(array<MenuItemStyle>[]()[], Int32) | Copie tous les éléments de l'objet MenuItemStyleCollection dans un tableau d'objets MenuItemStyle compatible unidimensionnel, en commençant à l'index spécifié dans le tableau cible. | .gif) | CreateKnownType | En cas de substitution dans une classe dérivée, crée une instance d'une classe qui implémente IStateManager. Le type d'objet créé repose sur le membre spécifié de la collection retournée par la méthode GetKnownTypes. (Hérité de StateManagedCollection.) | .gif) | Equals(Object) | Détermine si l'Object spécifié est égal à l'Object en cours. (Hérité de Object.) | .gif) | Finalize | Autorise un objet à tenter de libérer des ressources et d'exécuter d'autres opérations de netto***ge avant qu'il ne soit récupéré par l'opération garbage collection. (Hérité de Object.) | .gif) | GetEnumerator | Retourne un itérateur qui itère au sein de la collection StateManagedCollection. (Hérité de StateManagedCollection.) | .gif) | GetHashCode | Sert de fonction de hachage pour un type particulier. (Hérité de Object.) | .gif) | GetKnownTypes | En cas de substitution dans une classe dérivée, obtient un tableau de types IStateManager que la collection StateManagedCollection peut contenir. (Hérité de StateManagedCollection.) | .gif) | GetType | Obtient le Type de l'instance actuelle. (Hérité de Object.) | .gif) | IndexOf | Détermine l'index de l'objet MenuItemStyle spécifié dans la collection. | .gif) | Insert | Insère l'objet MenuItemStyle spécifié dans la collection à la position d'index spécifiée. | .gif) | MemberwiseClone | Crée une copie superficielle de l'objet Object actif. (Hérité de Object.) | .gif) | OnClear | En cas de substitution dans une classe dérivée, exécute une tâche supplémentaire avant que la méthode Clear supprime tous les éléments de la collection. (Hérité de StateManagedCollection.) | .gif) | OnClearComplete | En cas de substitution dans une classe dérivée, exécute une tâche supplémentaire une fois tous les éléments de la collection supprimés par la méthode Clear. (Hérité de StateManagedCollection.) | .gif) | OnInsert | En cas de substitution dans une classe dérivée, exécute une tâche supplémentaire avant la méthode Insert(Int32, Object) ou Add(Object) ajoute un élément à la collection. (Hérité de StateManagedCollection.) | .gif) | OnInsertComplete | En cas de substitution dans une classe dérivée, exécute une tâche supplémentaire après que la méthode Insert(Int32, Object) ou Add(Object) a ajouté un élément à la collection. (Hérité de StateManagedCollection.) | .gif) | OnRemove | En cas de substitution dans une classe dérivée, exécute toute tâche supplémentaire avant que la méthode Remove(Object) ou RemoveAt(Int32) supprime l'élément spécifié de la collection. (Hérité de StateManagedCollection.) | .gif) | OnRemoveComplete | En cas de substitution dans une classe dérivée, exécute toute tâche supplémentaire après que la méthode Remove(Object) ou RemoveAt(Int32) a supprimé l'élément spécifié de la collection. (Hérité de StateManagedCollection.) | .gif) | OnValidate | En cas de substitution dans une classe dérivée, valide un élément de la collection StateManagedCollection. (Hérité de StateManagedCollection.) | .gif) | Remove | Supprime de la collection l'objet MenuItemStyle spécifié. | .gif) | RemoveAt | Supprime de la collection l'objet MenuItemStyle situé à la position d'index spécifiée. | .gif) | SetDirty | Force la sérialisation de l'intégralité de la collection StateManagedCollection dans l'état d'affichage. (Hérité de StateManagedCollection.) | .gif) | SetDirtyObject | En cas de substitution dans une classe dérivée, commande à un object contenu dans la collection d'enregistrer l'intégralité de son état dans l'état d'affichage, plutôt que d'enregistrer uniquement des informations relatives aux modifications. (Hérité de StateManagedCollection.) | .gif) | ToString | Retourne une chaîne qui représente l'objet actuel. (Hérité de Object.) | Début

Implémentations d'interface explicite

Notes
La classe MenuItemStyleCollection est utilisée pour stocker et gérer une collection d'objets MenuItemStyle dans un contrôle Menu. Le contrôle Menu utilise la classe MenuItemStyleCollection comme type de données sous-jacent des propriétés LevelMenuItemStyles et LevelSelectedStyles. Les propriétés LevelMenuItemStyles et LevelSelectedStyles sont une alternative aux propriétés de style (telles que StaticMenuItemStyle). Ces propriétés sont respectivement appliquées à des éléments de menu normaux et à l'élément de menu sélectionné en fonction du niveau de l'élément de menu dans le menu. Le premier style de la collection correspond au style d'élément de menu du premier niveau du menu. Le deuxième style de la collection correspond au style d'élément de menu du deuxième niveau du menu, et ainsi de suite. Les propriétés LevelMenuItemStyles et LevelSelectedStyles sont plus souvent utilisées pour générer des menus dans lesquels les éléments de menu à un certain niveau ont la même apparence, qu'ils comportent ou non des sous-menus. La classe MenuItemStyleCollection hérite la plupart de ses membres de la classe StateManagedCollection. Pour plus d'informations sur les membres hérités, consultez StateManagedCollection.

Exemples
L'exemple de code suivant montre comment utiliser la classe MenuItemStyleCollection pour spécifier les paramètres de style pour les éléments de menu dans un contrôle Menu en fonction du niveau de l'élément de menu. Dans cet exemple, la propriété LevelMenuItemStyles est créée de manière déclarative, un objet MenuItemStyle est supprimé et un autre est ajouté à l'objet MenuItemStyleCollection.
<%@ 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 >
<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="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 >
<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>

Informations de version
.NET FrameworkPris en charge dans : 4, 3.5, 3.0, 2.0

Plateformes
Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows XP SP2 Édition x64, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

Sécurité des threads
Tous les membres static ( Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Voir aussi
|