[ContentProperty("Items")] [Handler(ContextMenu.IHandler)] public class ContextMenu : Menu, ISubmenu
Represents a context menu that can be shown typically when users right click or press the menu key on a control

Constructors

ContextMenu

#
public ContextMenu(IEnumerable<MenuItem> items)
Initializes a new instance of the ContextMenu class.

ContextMenu

#Since v2.10
public ContextMenu(IHandler handler, IEnumerable<MenuItem> items = null)
Initializes a new instance of the ContextMenu class with a specified handler.

ContextMenu

#
public ContextMenu(params MenuItem[] items)
Initializes a new instance of the ContextMenu class.

Fields

ClosedEvent

#
public const string ClosedEvent = "ContextMenu.Closed"
Event identifier for handlers when attaching the Closed event.

ClosingEvent

#
public const string ClosingEvent = "ContextMenu.Closing"
Event identifier for handlers when attaching the Closing event.

OpeningEvent

#
public const string OpeningEvent = "ContextMenu.Opening"
Event identifier for handlers when attaching the Opening event.

Properties

ControlObject

public object ControlObject { get; }
Gets the instance of the platform-specific object
inherited fromWidget
Remarks: This can sometimes be useful to get the platform-specific object. Some handlers may not have any backing object for its functionality, so this may be null. It is more preferred to use the Widget.Handler and cast that to the platform-specific handler class which can give you additional methods and helpers to do common tasks. For example, the Application object's handler for OS X has a AddFullScreenMenuItem property to specify if you want full screen support in your app.

DataContext

public object DataContext { get; set; }
Gets or sets the data context for this widget for binding
inherited fromBindableWidget
Remarks: Subclasses may override the standard behaviour so that hierarchy of widgets can be taken into account. For example, a Control may return the data context of a parent, if it is not set explicitly.
DataContext

Handler

public object Handler { get; }
Gets the platform-specific handler for this widget
inherited fromWidget

IncludeSystemItems

#Since v2.12
[DefaultValue(ContextMenuSystemItems.All)] public ContextMenuSystemItems IncludeSystemItems { get; set; }
Gets or sets which system items will be automatically included with the menu.
Remarks: Some operating systems, such as macOS, add their own contextual menu items - AutoFill, Services, and the like - to any context menu shown for (or assigned to) a control. Set this to ContextMenuSystemItems.None to show only the items you have added to Items. This applies both to menus shown via Show(Control, PointF?) and to menus assigned to a control using Control.ContextMenu.
The system items to include with the menu. Defaults to ContextMenuSystemItems.All

IsDataContextChanging

public bool IsDataContextChanging { get; set; }
Gets a value indicating that the BindableWidget.DataContext property is changing.
inherited fromBindableWidget
Remarks: This can be used to determine when to allow certain logic during the update of the data context. It is used to disable binding setters on the model when the data context changes so that a binding does not cause the view model to be updated when the state hasn't been fully set yet.
true if the DataContext is currently changing, false otherwise.

IsDisposed

public bool IsDisposed { get; }
Gets or sets a value indicating whether this Widget has been disposed.
inherited fromWidget
Remarks: When the widget is disposed, it can no longer be used.
true if this instance has been disposed; otherwise, false.

Items

#
public MenuItemCollection Items { get; }
Gets the menu items in the context menu

NativeHandle

public nint NativeHandle { get; }
Gets the native platform-specific handle for integration purposes
inherited fromWidget

Parent

public Widget Parent { get; protected internal set; }
Gets or sets the parent widget which this widget has been added to, if any
inherited fromBindableWidget
Remarks: When implementing child widgets that can participate in the context based binding (MVVM), You can set this to the parent widget when it is added or removed to it (usually via a collection). Note that you should typically provide a
public new [ParentWidget] Parent { get; }
property so that consumers of your API cannot set the parent to an invalid value.
The parent widget, or null if there is no parent

Platform

public Platform Platform { get; }
Gets the platform that was used to create the Widget.Handler for this widget
inherited fromWidget
Remarks: This gets set to the current Platform.Instance during the construction of the object

Properties

public PropertyStore Properties { get; }
Gets the dictionary of properties for this widget
inherited fromWidget

Style

public string Style { get; set; }
Gets or sets the style of this widget
inherited fromWidget
Remarks: Styles allow you to attach custom platform-specific logic to a widget. In your platform-specific assembly, use Add{H} to add the style logic with the same id.
// in your UI
var control = new Button { Style = "mystyle" };

// in your platform assembly
using Eto.Mac.Forms.Controls;

Styles.AddHandler<ButtonHandler>("mystyle", handler => {
	// this is where you can use handler.Control to set properties, handle events, etc.
	handler.Control.BezelStyle = NSBezelStyle.SmallSquare;
});

Trim

#
public bool Trim { get; set; }
Gets a value indicating whether this sub menu should trim its child menu items when loaded onto a form
Remarks: Trimming will collapse any duplicate splitter items. This is done so that you can easily merge your menus.
true to trim the child menu items; otherwise, false.
Trim

Methods

Dispose

protected virtual void Dispose(bool disposing)
Handles the disposal of this widget
inherited fromWidget
disposing (bool)True if the caller called Widget.Dispose() manually, false if being called from a finalizer

FindParent<T>

public T FindParent<T>(string id = null)
Finds a control in the parent hierarchy with the specified type and Widget.ID if specified
inherited fromBindableWidget
id (string = null)Identifier of the parent control to find, or null to ignore
The parent if found, or null if not found

FindParent

public Widget FindParent(Type type, string id = null)
Finds a control in the parent hierarchy with the specified type and Widget.ID if specified
inherited fromBindableWidget
type (Type)The type of control to find.
id (string = null)Identifier of the parent control to find, or null to find by type only.
The parent if found, or null if not found.

GetCallback

#
protected override object GetCallback()
Gets an instance of an object used to perform callbacks to the widget from handler implementations

Initialize

protected void Initialize()
Initializes the widget handler
inherited fromWidget
Remarks: This is typically called from the constructor after all of the logic is completed to construct the object. If your handler interface has the AutoInitializeAttribute set to false, then you are responsible for calling this method in your constructor after calling the creation method on your custom handler.

OnClosing

#
protected virtual void OnClosing(EventArgs e)
Raises the Closing event.

OnDataContextChanged

protected virtual void OnDataContextChanged(EventArgs e)
inherited fromBindableWidget
Remarks: Implementors may override this to fire this event on child widgets in a heirarchy. Alternatively, implement IBindableWidgetContainer for your widget and this will trigger any events on the children automatically. This allows a control to be bound to its own BindableWidget.DataContext, which would be set on one of the parent control(s).
e (EventArgs)Event arguments

OnLoad

#
protected internal override void OnLoad(EventArgs e)
Called when the menu is assigned to a control/window

OnOpening

#
protected virtual void OnOpening(EventArgs e)
Raises the Opening event.

OnPreLoad

protected internal virtual void OnPreLoad(EventArgs e)
Called before the menu is assigned to a control/window
inherited fromMenu

OnStyleChanged

protected virtual void OnStyleChanged(EventArgs e)
Handles when the Widget.Style is changed.
inherited fromWidget

OnUnLoad

#
protected internal override void OnUnLoad(EventArgs e)
Called when the menu is removed from a control/window

Show

#
public void Show(Control relativeTo, PointF? location)
Shows the context menu at the specified location relative to a control.
Remarks: Note that the operating system may move the context menu to make it fully visible.
relativeTo (Control)Control to show the menu relative to, or null to use screen co-ordinates for location
location (PointF?)Location to place the upper left of the context menu, or null to use the mouse position

Show

#
public void Show(Control relativeTo)
Show the context menu for the specified control, usually at the current mouse position.

Show

#
public void Show(PointF location)
Shows the context menu at the specified screen co-ordinates
Remarks: Note that the operating system may move the location of the menu to make it fully visible.
location (PointF)Location in screen co-ordinates to place the context menu

ToString

public override string ToString()
Gets a string that represents the current object with its ID if specified.
inherited fromWidget
A string value indicating the type and ID (if specified) of this widget.
Object.ToString

Unbind

public virtual void Unbind()
Unbinds any bindings in the BindableWidget.Bindings collection and removes the bindings
inherited fromBindableWidget

UpdateBindings

public virtual void UpdateBindings(BindingUpdateMode mode = BindingUpdateMode.Source)
Updates all bindings in this widget
inherited fromBindableWidget
Remarks: When you implement IBindableWidgetContainer, this will also update bindings for all of its children.
mode (BindingUpdateMode = BindingUpdateMode.Source)

Events

Closed

#
public event EventHandler<EventArgs> Closed
Occurs when the context menu is closed/dismissed, after the menu item has been selected and its click event is triggered.

Closing

#
public event EventHandler<EventArgs> Closing
Occurs before the context menu is closed/dismissed when the user clicks an item, but before the menu item's click event is triggered.

DataContextChanged

public event EventHandler<EventArgs> DataContextChanged
Event to handle when the BindableWidget.DataContext has changed
inherited fromBindableWidget
Remarks: This may be fired in the event of a parent in the hierarchy setting the data context. For example, the Container widget fires this event when it's event is fired.
DataContextChanged

Opening

#
public event EventHandler<EventArgs> Opening
Occurs when the context menu is opening, before it is shown.