Version

Opening and Showing xamContextMenu

By default, the xamContextMenu™ control will be displayed when your end users release the right-mouse button. The ContextMenuManager object gives you several options to change this default behavior.

  • You can set the ContextMenuManager object’s ModifierKeys property to a bitwise combination of modifier keys that your end users have to hold before activating xamContextMenu.

  • You can set the ContextMenuManager object’s OpenMode property to an OpenMode enum value to determine the mouse button that activates xamContextMenu.

  • You can use the Infragistics Commanding Framework along with the xamContextMenuCommandSource object and the Open command to activate xamContextMenu. This option gives you the flexibility to choose any event exposed by a control to activate xamContextMenu. If you choose this option, you should set the ContextMenuManager object’s OpenMode property to None.

The following code gives you an example how you can change the default (right click) opening mode to left mouse click and set the ModifierKeys property to a combination of Control and Shift key.

In XAML:

<TextBox Name="textBox1">
    <!--
    Example of using the Infragistics Commanding Framework to open the context menu:
    -->
    <!--
    <igWPF:Commanding.Command>
        <ig:XamContextMenuCommandSource
            CommandType="Open"
            EventName="SelectionChanged"
            TargetName="contextMenu1" />
    </igWPF:Commanding.Command>
    -->
    <ig:ContextMenuService.Manager>
        <!--If you use the Infragistics Commanding Framework, you should set the OpenMode property to None-->
        <ig:ContextMenuManager ModifierKeys="Control, Shift" OpenMode="LeftClick">
            <ig:ContextMenuManager.ContextMenu>
                <ig:XamContextMenu Name="contextMenu1">
                    <ig:XamMenuItem Header="Font" />
                    <ig:XamMenuItem Header="Formatting" />
                </ig:XamContextMenu>
            </ig:ContextMenuManager.ContextMenu>
        </ig:ContextMenuManager>
    </ig:ContextMenuService.Manager>
</TextBox>

In Visual Basic:

Imports Infragistics.Controls.Menus
Imports Infragistics
...
Dim contextMenuManager1 As New ContextMenuManager()
contextMenuManager1.ModifierKeys = ModifierKeys.Control Or ModifierKeys.Shift
contextMenuManager1.OpenMode = OpenMode.LeftClick
'TODO: Create a xamContextMenu and add XamMenuItem objects to it.
'TODO: Set the ContextMenuManager object's ContextMenu property to the xamContextMenu control.
ContextMenuService.SetManager(textBox1, contextMenuManager1)
...

In C#:

using Infragistics.Controls.Menus;
using Infragistics;
...
ContextMenuManager contextMenuManager1 = new ContextMenuManager
{
    ModifierKeys = ModifierKeys.Control | ModifierKeys.Shift,
    OpenMode = OpenMode.LeftClick
};
//TODO: Create a xamContextMenu and add XamMenuItem objects to it.
//TODO: Set the ContextMenuManager object's ContextMenu property to the xamContextMenu control.
ContextMenuService.SetManager(textBox1, contextMenuManager1);
...