Context Menus
Context menus are supported by both GraphEditorInputMode and GraphViewerInputMode.
The provided callbacks allow you to use a context menu implementation from any web UI framework, or a custom implementation of your choice. yFiles for HTML does not come with a context menu UI widget, though a simple implementation is provided with the Context Menu demo. The demo sources show how to register the context menu with the input modes of yFiles for HTML, and illustrates how a the menu implementation could look like.
A context menu can be opened and populated in a handler for
GraphEditorInputMode’s or GraphViewerInputMode’s PopulateItemContextMenu event.
This event occurs after the user has requested a context menu, but before
the menu is actually displayed.
This allows you to create context menus that are, well, contextual to the item
that has been right-clicked by appropriately populating the context menu with MenuItem
s:
The contextMenuItems property on GraphEditorInputMode and GraphViewerInputMode controls for which items the context menu events trigger when clicked. A more specific distinction can be obtained by overriding shouldPopulateContextMenu.
The actual work is done by the ContextMenuInputMode which is a child input mode for both GraphEditorInputMode and GraphViewerInputMode.
Further customizations can be done on the ContextMenuInputMode. GraphEditorInputMode and GraphViewerInputMode trigger the PopulateItemContextMenu upon ContextMenuInputMode’s PopulateMenu event. You can override the actual dispatching method, onPopulateMenu for customizations.
- validMenuLocationHitTestable
- specifies the area in which a context menu can be requested.