MenuItemStyleCollection Classe

Definição

Representa uma coleção de objetos MenuItemStyle em um controle Menu.Represents a collection of MenuItemStyle objects in a Menu control. Essa classe não pode ser herdada.This class cannot be inherited.

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
Herança
MenuItemStyleCollection

Exemplos

O exemplo de código a seguir demonstra como usar a MenuItemStyleCollection classe para especificar as configurações de estilo para os itens de menu em um Menu controle com base no nível do item de menu.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. Neste exemplo, a LevelMenuItemStyles propriedade é criada declarativamente e um MenuItemStyle objeto é removido e outro adicionado ao MenuItemStyleCollection objeto.In this example, the LevelMenuItemStyles property is created declaratively, and one MenuItemStyle object is removed and another added to the MenuItemStyleCollection object.


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

Comentários

A MenuItemStyleCollection classe é usada para armazenar e gerenciar uma coleção de MenuItemStyle objetos em um Menu controle.The MenuItemStyleCollection class is used to store and manage a collection of MenuItemStyle objects in a Menu control. O Menu controle usa a MenuItemStyleCollection classe como o tipo de dados subjacente das LevelMenuItemStyles LevelSelectedStyles Propriedades e.The Menu control uses the MenuItemStyleCollection class as the underlying data type of the LevelMenuItemStyles and LevelSelectedStyles properties.

As LevelMenuItemStyles LevelSelectedStyles Propriedades e são uma alternativa para as propriedades de estilo individuais (como StaticMenuItemStyle ).The LevelMenuItemStyles and LevelSelectedStyles properties are an alternative to the individual style properties (such as StaticMenuItemStyle). Essas propriedades são aplicadas a itens de menu normais e ao item de menu selecionado, respectivamente, com base no nível do item de menu no menu.These properties are applied to regular menu items and the selected menu item, respectively, based on the menu item's level in the menu. O primeiro estilo na coleção corresponde ao estilo do item de menu para o primeiro nível do menu.The first style in the collection corresponds to the menu item style for the first level of the menu. O segundo estilo na coleção corresponde ao estilo do item de menu para o segundo nível do menu, e assim por diante.The second style in the collection corresponds to the menu item style for the second level of the menu, and so on. As LevelMenuItemStyles LevelSelectedStyles Propriedades e são usadas com mais frequência para gerar menus em que os itens de menu em um determinado nível têm a mesma aparência, independentemente de terem menus.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.

A MenuItemStyleCollection classe herda a maioria de seus membros da StateManagedCollection classe.The MenuItemStyleCollection class inherits most of its members from the StateManagedCollection class. Para obter mais informações sobre os membros herdados, consulte StateManagedCollection .For more information on the inherited members, see StateManagedCollection.

Propriedades

Count

Obtém o número de elementos contidos na coleção StateManagedCollection.Gets the number of elements contained in the StateManagedCollection collection.

(Herdado de StateManagedCollection)
Item[Int32]

Obtém o objeto MenuItemStyle no índice especificado da coleção.Gets the MenuItemStyle object at the specified index from the collection.

Métodos

Add(MenuItemStyle)

Acrescenta o objeto MenuItemStyle especificado ao final da coleção atual.Appends the specified MenuItemStyle object to the end of the current collection.

Clear()

Remove todos os itens da coleção StateManagedCollection.Removes all items from the StateManagedCollection collection.

(Herdado de StateManagedCollection)
Contains(MenuItemStyle)

Determina se o objeto MenuItemStyle especificado está na coleção.Determines whether the specified MenuItemStyle object is in the collection.

CopyTo(Array, Int32)

Copia os elementos da coleção StateManagedCollection para uma matriz, começando em um índice de matriz específico.Copies the elements of the StateManagedCollection collection to an array, starting at a particular array index.

(Herdado de StateManagedCollection)
CopyTo(MenuItemStyle[], Int32)

Copia todos os itens do objeto MenuItemStyleCollection para uma matriz unidimensional compatível de objetos MenuItemStyle, começando no índice especificado na matriz de destino.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.

CreateKnownType(Int32)

Quando substituído em uma classe derivada, cria uma instância de uma classe que implementa IStateManager.When overridden in a derived class, creates an instance of a class that implements IStateManager. O tipo de objeto criado se baseia no membro especificado da coleção retornada pelo método GetKnownTypes().The type of object created is based on the specified member of the collection returned by the GetKnownTypes() method.

(Herdado de StateManagedCollection)
Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object.

(Herdado de Object)
GetEnumerator()

Retorna um iterador que itera por meio da coleção StateManagedCollection.Returns an iterator that iterates through the StateManagedCollection collection.

(Herdado de StateManagedCollection)
GetHashCode()

Serve como a função de hash padrão.Serves as the default hash function.

(Herdado de Object)
GetKnownTypes()

Quando substituído em uma classe derivada, obtém uma matriz de tipos IStateManager que a coleção StateManagedCollection pode conter.When overridden in a derived class, gets an array of IStateManager types that the StateManagedCollection collection can contain.

(Herdado de StateManagedCollection)
GetType()

Obtém o Type da instância atual.Gets the Type of the current instance.

(Herdado de Object)
IndexOf(MenuItemStyle)

Determina o índice do objeto MenuItemStyle especificado na coleção.Determines the index of the specified MenuItemStyle object in the collection.

Insert(Int32, MenuItemStyle)

Insere o objeto MenuItemStyle especificado na coleção no local do índice especificado.Inserts the specified MenuItemStyle object into the collection at the specified index location.

MemberwiseClone()

Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object.

(Herdado de Object)
OnClear()

Quando substituído em uma classe derivada, executa o trabalho adicional antes do método Clear() remover todos os itens da coleção.When overridden in a derived class, performs additional work before the Clear() method removes all items from the collection.

(Herdado de StateManagedCollection)
OnClearComplete()

Quando substituído em uma classe derivada, executa o trabalho adicional após o método Clear() terminar a remoção de todos os itens da coleção.When overridden in a derived class, performs additional work after the Clear() method finishes removing all items from the collection.

(Herdado de StateManagedCollection)
OnInsert(Int32, Object)

Quando substituído em uma classe derivada, executa o trabalho adicional antes do método IList.Insert(Int32, Object) ou IList.Add(Object) adicionar um item à coleção.When overridden in a derived class, performs additional work before the IList.Insert(Int32, Object) or IList.Add(Object) method adds an item to the collection.

(Herdado de StateManagedCollection)
OnInsertComplete(Int32, Object)

Quando substituído em uma classe derivada, executa o trabalho adicional após o método IList.Insert(Int32, Object) ou IList.Add(Object) adicionar um item à coleção.When overridden in a derived class, performs additional work after the IList.Insert(Int32, Object) or IList.Add(Object) method adds an item to the collection.

(Herdado de StateManagedCollection)
OnRemove(Int32, Object)

Quando substituído em uma classe derivada, executa o trabalho adicional antes do método IList.Remove(Object) ou IList.RemoveAt(Int32) remover o item especificado da coleção.When overridden in a derived class, performs additional work before the IList.Remove(Object) or IList.RemoveAt(Int32) method removes the specified item from the collection.

(Herdado de StateManagedCollection)
OnRemoveComplete(Int32, Object)

Quando substituído em uma classe derivada, executa o trabalho adicional após o método IList.Remove(Object) ou IList.RemoveAt(Int32) remover o item especificado da coleção.When overridden in a derived class, performs additional work after the IList.Remove(Object) or IList.RemoveAt(Int32) method removes the specified item from the collection.

(Herdado de StateManagedCollection)
OnValidate(Object)

Quando substituído em uma classe derivada, valida um elemento da coleção StateManagedCollection.When overridden in a derived class, validates an element of the StateManagedCollection collection.

(Herdado de StateManagedCollection)
Remove(MenuItemStyle)

Remove o objeto MenuItemStyle especificado da coleção.Removes the specified MenuItemStyle object from the collection.

RemoveAt(Int32)

Remove o objeto MenuItemStyle no local do índice especificado da coleção.Removes the MenuItemStyle object at the specified index location from the collection.

SetDirty()

Força a coleção StateManagedCollection inteira a ser serializada no estado de exibição.Forces the entire StateManagedCollection collection to be serialized into view state.

(Herdado de StateManagedCollection)
SetDirtyObject(Object)

Quando substituído em uma classe derivada, instrui um object contido na coleção a registrar seu estado inteiro para o estado de exibição, em vez de registrar apenas informações alteradas.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.

(Herdado de StateManagedCollection)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object.

(Herdado de Object)

Implantações explícitas de interface

ICollection.Count

Obtém o número de elementos contidos na coleção StateManagedCollection.Gets the number of elements contained in the StateManagedCollection collection.

(Herdado de StateManagedCollection)
ICollection.IsSynchronized

Obtém um valor que indica se a coleção StateManagedCollection é sincronizada (thread-safe).Gets a value indicating whether the StateManagedCollection collection is synchronized (thread safe). Este método retorna false em todos os casos.This method returns false in all cases.

(Herdado de StateManagedCollection)
ICollection.SyncRoot

Obtém um objeto que pode ser usado para sincronizar o acesso à coleção StateManagedCollection.Gets an object that can be used to synchronize access to the StateManagedCollection collection. Este método retorna null em todos os casos.This method returns null in all cases.

(Herdado de StateManagedCollection)
IEnumerable.GetEnumerator()

Retorna um iterador que itera por meio da coleção StateManagedCollection.Returns an iterator that iterates through the StateManagedCollection collection.

(Herdado de StateManagedCollection)
IList.Add(Object)

Adiciona um item à coleção StateManagedCollection.Adds an item to the StateManagedCollection collection.

(Herdado de StateManagedCollection)
IList.Clear()

Remove todos os itens da coleção StateManagedCollection.Removes all items from the StateManagedCollection collection.

(Herdado de StateManagedCollection)
IList.Contains(Object)

Determina se a coleção StateManagedCollection contém um valor específico.Determines whether the StateManagedCollection collection contains a specific value.

(Herdado de StateManagedCollection)
IList.IndexOf(Object)

Determina o índice de um item especificado na coleção StateManagedCollection.Determines the index of a specified item in the StateManagedCollection collection.

(Herdado de StateManagedCollection)
IList.Insert(Int32, Object)

Insere um item na coleção StateManagedCollection no índice especificado.Inserts an item into the StateManagedCollection collection at the specified index.

(Herdado de StateManagedCollection)
IList.IsFixedSize

Obtém um valor que indica se a coleção StateManagedCollection tem um tamanho fixo.Gets a value indicating whether the StateManagedCollection collection has a fixed size. Este método retorna false em todos os casos.This method returns false in all cases.

(Herdado de StateManagedCollection)
IList.IsReadOnly

Obtém um valor que indica se a coleção StateManagedCollection é somente leitura.Gets a value indicating whether the StateManagedCollection collection is read-only.

(Herdado de StateManagedCollection)
IList.Item[Int32]

Obtém o elemento IStateManager no índice especificado.Gets the IStateManager element at the specified index.

(Herdado de StateManagedCollection)
IList.Remove(Object)

Remove a primeira ocorrência do objeto especificado da coleção StateManagedCollection.Removes the first occurrence of the specified object from the StateManagedCollection collection.

(Herdado de StateManagedCollection)
IList.RemoveAt(Int32)

Remove o elemento IStateManager no índice especificado.Removes the IStateManager element at the specified index.

(Herdado de StateManagedCollection)
IStateManager.IsTrackingViewState

Obtém um valor que indica se a coleção StateManagedCollection está salvando alterações no estado de exibição.Gets a value indicating whether the StateManagedCollection collection is saving changes to its view state.

(Herdado de StateManagedCollection)
IStateManager.LoadViewState(Object)

Restaura o estado de exibição salvo anteriormente da coleção StateManagedCollection e o itens IStateManager que ele contém.Restores the previously saved view state of the StateManagedCollection collection and the IStateManager items it contains.

(Herdado de StateManagedCollection)
IStateManager.SaveViewState()

Salva as alterações na coleção StateManagedCollection e cada objeto IStateManager que ela contém, desde o momento em que a página foi postada novamente no servidor.Saves the changes to the StateManagedCollection collection and each IStateManager object it contains since the time the page was posted back to the server.

(Herdado de StateManagedCollection)
IStateManager.TrackViewState()

Faz com que a coleção StateManagedCollection e os objetos IStateManager que ela contém controlem as alterações realizadas no estado de exibição, para que elas possam ser mantidas em todas as solicitações para a mesma página.Causes the StateManagedCollection collection and each of the IStateManager objects it contains to track changes to their view state so they can be persisted across requests for the same page.

(Herdado de StateManagedCollection)

Métodos de Extensão

Cast<TResult>(IEnumerable)

Converte os elementos de um IEnumerable para o tipo especificado.Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filtra os elementos de um IEnumerable com base em um tipo especificado.Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Habilita a paralelização de uma consulta.Enables parallelization of a query.

AsQueryable(IEnumerable)

Converte um IEnumerable em um IQueryable.Converts an IEnumerable to an IQueryable.

Aplica-se a

Confira também