Version

Set xamContextMenu’s Location

The xamContextMenu™ control exposes several properties that emulate the placement of a ContextMenu control in Microsoft® WPF™. The xamContextMenu control’s placement is determined by a combination of the following placement-related properties:

  • Placement - Determines the alignment of xamContextMenu relative to its placement target. However, if you do not explicitly set this property, it will default to MouseClick and ignore the PlacementTarget and PlacementRectangle properties. The screen shot below illustrates the locations for the different PlacementMode enum values. The green square in the screen shot represents the placement target.

xamContextMenu Set xamContextMenus Location 01.png
  • PlacementTarget - Determines the UIElement that xamContextMenu uses as its starting location before it applies the other placement-related properties. If you do not explicitly set this property, the control you attach xamContextMenu to will be the default placement target.

  • PlacementRectangle - You can set this property to a Rect structure to define a rectangular area relative to the placement target that the context menu uses for alignment. In XAML, you can set this property to a comma-delimited string of values where the first value is the left x-coordinate, the second value is the top y-coordinate, the third value is the width, and the fourth value is the height.

  • HorizontalOffset - You can set this property to a positive numeric value to determine the horizontal distance between the context menu and its placement. The horizontal offset is applied after the Placement, PlacementTarget, and PlacementRectangle properties have been applied.

  • VerticalOffset - You can set this property to a positive numeric value to determine the vertical distance between the context menu and its placement. The vertical offset is applied after the Placement, PlacementTarget, and PlacementRectangle properties have been applied.

The following example code demonstrates how to set the placement of xamContextMenu. The code to attach xamContextMenu has been omitted to keep the example concise. For a code example on attaching xamContextMenu to a control, read Adding xamContextMenu to Your Page.

In XAML:

<ig:XamContextMenu Placement="AlignedBottom">
    <!--TODO: Add XamMenuItem objects here-->
</ig:XamContextMenu>

In Visual Basic:

Dim xamContextMenu1 As New XamContextMenu With {.Placement = PlacementMode.AlignedBottom}
'TODO: Add XamMenuItem objects to the context menu

In C#:

XamContextMenu xamContextMenu1 = new XamContextMenu
{
    Placement = PlacementMode.AlignedBottom
};
//TODO: Add XamMenuItem objects to the context menu