MenuEventHandler Delegar
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Representa o método que gere o MenuItemClick evento ou MenuItemDataBound evento de um Menu controlo.
public delegate void MenuEventHandler(System::Object ^ sender, MenuEventArgs ^ e);
public delegate void MenuEventHandler(object sender, MenuEventArgs e);
type MenuEventHandler = delegate of obj * MenuEventArgs -> unit
Public Delegate Sub MenuEventHandler(sender As Object, e As MenuEventArgs)
Parâmetros
- sender
- Object
A origem do evento.
A MenuEventArgs que contém os dados do evento.
Exemplos
O exemplo de código seguinte demonstra como usar o MenuEventHandler delegado para registar programaticamente um gestor de eventos para o MenuItemClick evento de um Menu controlo. Para que este exemplo funcione corretamente, deve copiar os dados do mapa de sites abaixo para um ficheiro chamado Web.sitemap.
<%@ 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)
{
// Create a new Menu control.
Menu newMenu = new Menu();
// Set the properties of the Menu control.
newMenu.ID = "NavigationMenu";
newMenu.Orientation = Orientation.Vertical;
newMenu.Target = "_blank";
// Specify the data source for the menu.
newMenu.DataSourceID = "MenuSource";
// Programmatically register the event-handling method
// for the MenuItemClick event of a Menu control.
newMenu.MenuItemClick += new MenuEventHandler(this.NavigationMenu_MenuItemClick);
// Add the Menu control to the Controls collection
// of the PlaceHolder control.
MenuPlaceHolder.Controls.Add(newMenu);
}
void NavigationMenu_MenuItemClick(Object sender, MenuEventArgs e)
{
// Display the text of the menu item selected by the user.
Message.Text = "You selected " + e.Item.Text + ".";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MenuEventHandler Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuEventHandler Example</h3>
<asp:placeholder id="MenuPlaceHolder"
runat="server"/>
<asp:sitemapdatasource id="MenuSource"
runat="server"/>
<hr/>
<asp:label id="Message"
runat="server"/>
</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)
' Create a new Menu control.
Dim newMenu As New Menu()
' Set the properties of the Menu control.
newMenu.ID = "NavigationMenu"
newMenu.Orientation = Orientation.Vertical
newMenu.Target = "_blank"
' Specify the data source for the menu.
newMenu.DataSourceID = "MenuSource"
' Programmatically register the event-handling method
' for the MenuItemClick event of a Menu control.
AddHandler newMenu.MenuItemClick, AddressOf NavigationMenu_MenuItemClick
' Add the Menu control to the Controls collection
' of the PlaceHolder control.
MenuPlaceHolder.Controls.Add(newMenu)
End Sub
Sub NavigationMenu_MenuItemClick(ByVal sender As Object, ByVal e As MenuEventArgs)
' Display the text of the menu item selected by the user.
Message.Text = "You selected " & e.Item.Text & "."
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MenuEventHandler Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuEventHandler Example</h3>
<asp:placeholder id="MenuPlaceHolder"
runat="server"/>
<asp:sitemapdatasource id="MenuSource"
runat="server"/>
<hr/>
<asp:label id="Message"
runat="server"/>
</form>
</body>
</html>
Segue-se um exemplo de dados de mapa de sítios para o exemplo anterior.
<siteMap>
<siteMapNode title="Home"
description="Home">
<siteMapNode title="Music"
description="Music">
<siteMapNode title="Classical"
description="Classical"/>
<siteMapNode title="Rock"
description="Rock"/>
<siteMapNode title="Jazz"
description="Jazz"/>
</siteMapNode>
<siteMapNode title="Movies"
description="Movies">
<siteMapNode title="Action"
description="Action"/>
<siteMapNode title="Drama"
description="Drama"/>
<siteMapNode title="Musical"
description="Musical"/>
</siteMapNode>
</siteMapNode>
</siteMap>
Observações
A MenuEventHandler classe é usada para representar o método que gere os eventos na tabela seguinte.
| Event | Description |
|---|---|
| MenuItemClick | Ocorre quando um item do menu é clicado. Este evento é frequentemente usado para sincronizar um Menu controlo com outro controlo na página. |
| MenuItemDataBound | Ocorre quando um item do menu está associado a dados. Este evento é comumente usado para modificar um item de menu antes de ser renderizado num Menu controlo. |
Quando cria um MenuEventHandler delegado, identifica o método que irá gerir o evento. Para associar o evento ao seu gestor de eventos, adicione uma instância do delegado ao evento. O gestor de eventos é chamado sempre que o evento ocorre, a menos que remova o delegado. Para mais informações sobre os delegados handlers de eventos, consulte Gestão e Angariação de Eventos.
Métodos da Extensão
| Name | Description |
|---|---|
| GetMethodInfo(Delegate) |
Obtém um objeto que representa o método representado pelo delegado especificado. |