Color legend plain property dependency property method event
A menu that opens at the mouse on a right click, drawn above everything. Its items are ContextMenuItems, separators, or the objects of an ItemsSource; an item can be checkable and can open a sub-menu.
ContextMenu derives from BaseElement and has its members too. The lists and menus page shows it in context, with code and screenshots.
Names are colored by what they are: a plain property, a method, an event or a dependency property, which a style, a binding or an animation can set.
Properties
BorderStyle 馃爢
BorderStyle 路 The style of the border around the items. By default a white background with a 1 unit dark gray border.
CheckIconStyle 馃爢
ImageStyle 路 The style of the check mark of a checked item. By default an 8 by 8 unit dark gray square.
ExpandIconStyle 馃爢
ImageStyle 路 The style of the arrow of an item with a sub-menu. By default a 6 by 8 unit dark gray block at the right end; with a Source it is that picture, as in the screenshot.
GeneralMouseCursorsSet 馃爢
MouseCursorsSet 路 Static. The cursors of every element of this style type; null (the default) falls back to DefaultMouseCursorsSet.
GeneralStyle 馃爢
ContextMenuStyle 路 Static. The style of every element of this style type. It starts as a copy of the framework defaults; changing one of its properties updates every such element, a property it leaves unset takes its default.
IsOpen 馃爢
bool 路 Read-only. Whether the menu is open.
Items 馃爢
IReadOnlyList<BaseElement> 路 Read-only. The items and separators of the menu, in order.
ItemsSource 馃爢
IEnumerable 路 The objects to show, one item each. A BindableCollection<T> is followed.
ItemsTemplate 馃爢
IItemsTemplate 路 Makes the content of the item of each ItemsSource object; a label with the object鈥檚 text when none is set.
ListBoxStyle 馃爢
ListBoxStyle 路 The style of the list of the items. By default transparent rows, highlighted in light blue under the mouse and when selected.
MarginFromMouseCursor 馃爢
Margin 路 An offset added to the point the menu opens at: Left to the x, Top to the y, in units.
MouseCursorsSet 馃爢
MouseCursorsSet 路 Read-only. The cursors the element shows: its override, else the set given to the control it is a part of, else its type鈥檚 general set, else DefaultMouseCursorsSet.
MouseCursorsSetOverride 馃爢
MouseCursorsSet 路 The cursors of this element only, passed on to its parts that have none of their own.
ParentItem 馃爢
ContextMenuItem 路 Read-only. The item whose sub-menu this menu is, null for the menu of an element.
Placement 馃爢
ContextMenuPlacement 路 On which side of the point the menu opens. BottomRight by default.
StyleOverride 馃爢
ContextMenuStyle 路 A style for this element only, applied over the general style. Setting it to null takes its values back out.
SubMenusOpenType 馃爢
ContextMenuSubMenusOpenType 路 Whether the sub-menus of this menu鈥檚 items open on hover (OnHover, the default) or on click.
Methods
ContextMenu() 馃爢
ContextMenu(string name = null) 路 Creates a closed menu. The name is used by GetElementByName.
| Parameter | Type | Description |
|---|---|---|
name |
string |
The element鈥檚 Name, which GetElementByName finds it by. Default: null. |
AddItem() 馃爢
AddItem(BaseElement item) 路 Adds an item at the end. A ContextMenuItem or Separator is added as is, another element is put in an item. Does nothing while an ItemsSource is set.
| Parameter | Type | Description |
|---|---|---|
item |
BaseElement |
The element to add. |
AddItemAt() 馃爢
AddItemAt(BaseElement item, int index) 路 Inserts an item at the index.
| Parameter | Type | Description |
|---|---|---|
item |
BaseElement |
The element to insert. |
index |
int |
The position to insert it at: 0 for the first, the number of items for the end. |
AddItemsRange() 馃爢
AddItemsRange(IEnumerable<BaseElement> items) 路 Adds items at the end.
| Parameter | Type | Description |
|---|---|---|
items |
IEnumerable<BaseElement> |
The elements to add, in order. |
AddItemsRangeAt() 馃爢
AddItemsRangeAt(IEnumerable<BaseElement> items, int index) 路 Inserts items at the index.
| Parameter | Type | Description |
|---|---|---|
items |
IEnumerable<BaseElement> |
The elements to insert, in order. |
index |
int |
The position of the first one: 0 for the first, the number of items for the end. |
AddTextItem() 馃爢
AddTextItem(string text) 路 Adds an item showing the text in a label and returns it, to handle its OnClick, make it checkable or give it a SubMenu. The menu made it, so it is disposed when it is removed. Does nothing and returns null while an ItemsSource is set.
| Parameter | Type | Description |
|---|---|---|
text |
string |
The text of the item鈥檚 label. |
ClearItems() 馃爢
ClearItems() 路 Removes every item.
Close() 馃爢
Close() 路 Closes the menu with its open sub-menus, and gives the keyboard back to the element that had it before. On a sub-menu it closes only that sub-menu.
Open() 馃爢
Open(Point position) 路 Opens the menu at a point of the screen, placed by Placement and MarginFromMouseCursor and kept on the screen. Only a menu in the element tree that can take the keyboard opens; a sub-menu doesn鈥檛.
| Parameter | Type | Description |
|---|---|---|
position |
Point |
The point of the screen to open the menu at, in units. |
RemoveItem() 馃爢
RemoveItem(BaseElement item) 路 Removes the item, or the item made around the element.
| Parameter | Type | Description |
|---|---|---|
item |
BaseElement |
The element to take out. |
RemoveItemAt() 馃爢
RemoveItemAt(int index) 路 Removes the item at the index.
| Parameter | Type | Description |
|---|---|---|
index |
int |
The index of the item to take out. |
RemoveItemsRangeAt() 馃爢
RemoveItemsRangeAt(int index, int count) 路 Removes count items from the index on.
| Parameter | Type | Description |
|---|---|---|
index |
int |
The index of the first item to take out. |
count |
int |
The number of items to take out. |
Events
OnItemSelect 馃爢
(BaseElement sender, ContextMenuItem item) 路 An item of the menu or of one of its sub-menus is chosen. It is raised by the menu of the element; the sender is the menu the item is in.
| Parameter | Type | Description |
|---|---|---|
sender |
BaseElement |
The menu the item is in: the element鈥檚 menu or one of its sub-menus. |
item |
ContextMenuItem |
The chosen item. |