ContextMenu.PlacementTarget Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
The element relative to which the ContextMenu is positioned when it opens. The default is null
.
- Attributes
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
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.
Item | Value |
---|---|
Identifier field | PlacementTargetProperty |
Metadata properties set to true |
None |
Product | Versions |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9, 10 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: