This topic has not yet been rated - Rate this topic

AddMenuItemEventArgs Class

System.Object
  System.EventArgs
    Microsoft.SharePoint.WebControls.AddMenuItemEventArgs

Namespace:  Microsoft.SharePoint.WebControls
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
public sealed class AddMenuItemEventArgs : EventArgs
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
AddMenuItemEventArgs
Description

The Microsoft.SharePoint.WebControls.AddMenuItemEventArgs sealed class inherits from the System.EventArgs class which permits AddMenuItemEventArgs to propagate event particular data. In this specific case, we are concerned with when a Microsoft.SharePoint.WebControls.MenuItemTemplate object is added to a consumer Microsoft.SharePoint.WebControls.MenuTemplate object. Since we are only providing a MenuItemTemplate to the consumer, the AddMenuItemEventArgs is composed of one public MenuItemTemplate property intializing one MenuItemTemplate in the constructor.

The Usage Scenario

The primary use of the AddMenuItemEventArgs class is when creating custom Menus, more specifically those classes that inherit from the Microsoft.SharePoint.WebControls.MenuTemplate class. If you have a class decorated with that derivation, you can globally declare the event handler and use it to respond to MenuItemTemplate addition events. You can see that since we are inheriting from the MenuTemplate class, we can trip the event handler consuming a reference to the current class instance as well as the AddMenuItemEventArgsEventHandler object. This will add the MenuItemTemplate with the AddMenuItemEventArgs to the current MenuTemplate class instance. 

C# Code Example

private EventHandler<AddMenuItemEventArgs> AddingMenuItem;
private void WhenAddingMenuItem(AddMenuItemEventArgs e)
{
if (AddingMenuItem != null)
{
AddingMenuItem(this, e);
}
}

Visual Basic .NET Code Example

Private AddingMenuItem As EventHandler(Of AddMenuItemEventArgs)
Private Sub WhenAddingMenuItem(ByVal e As AddMenuItemEventArgs)
RaiseEvent AddingMenuItem(Me, e)
End Sub

Adam Buenz
SharePoint Foundation MVP - http://www.sharepointsecurity.com