ContextMenu.PlacementTarget Property

Definition

Gets or sets the UIElement relative to which the ContextMenu is positioned when it opens.

public:
 property System::Windows::UIElement ^ PlacementTarget { System::Windows::UIElement ^ get(); void set(System::Windows::UIElement ^ value); };
[System.ComponentModel.Bindable(true)]
public System.Windows.UIElement PlacementTarget { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.PlacementTarget : System.Windows.UIElement with get, set
Public Property PlacementTarget As UIElement

Property Value

The element relative to which the ContextMenu is positioned when it opens. The default is null.

Attributes

Examples

The target of a ContextMenu is its parent. The following examples show how to use the PlacementTarget property to find the parent of a ContextMenu.

ContextMenu cm = (ContextMenu)sender;
target = cm.PlacementTarget;
Dim cm As ContextMenu = CType(sender, ContextMenu)
target = cm.PlacementTarget
ContextMenu cm = (ContextMenu)ContextMenu.ItemsControlFromItemContainer                   ((MenuItem)e.OriginalSource);
UIElement placementTarget = cm.PlacementTarget;
Dim cm As ContextMenu = CType(ContextMenu.ItemsControlFromItemContainer (CType(e.OriginalSource, MenuItem)), ContextMenu)
Dim placementTarget As UIElement = cm.PlacementTarget

Remarks

When the ContextMenu is assigned to the FrameworkElement.ContextMenu or FrameworkContentElement.ContextMenu property, the ContextMenuService changes this value of this property to the owning FrameworkElement or FrameworkContentElement when the ContextMenu opens. To use a different UIElement, set the ContextMenuService.PlacementTarget property.

Dependency Property Information

Identifier field PlacementTargetProperty
Metadata properties set to true None

Applies to

See also