ContextMenu.PlacementTarget Property

Gets or sets the PlacementTarget property of a ContextMenu.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:

public UIElement PlacementTarget { get; set; }
/** @property */
public UIElement get_PlacementTarget ()

/** @property */
public void set_PlacementTarget (UIElement value)

public function get PlacementTarget () : UIElement

public function set PlacementTarget (value : UIElement)

    <UIElement .../>

Property Value

A PlacementTarget. The default value is null.

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;

ContextMenu cm = (ContextMenu)ContextMenu.ItemsControlFromItemContainer                   ((MenuItem)e.OriginalSource);
UIElement placementTarget = cm.PlacementTarget;

For a complete code example that attaches a ContextMenu to each item of a TabControl, see TabControl with ContextMenus Sample.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions