ContextMenu.PlacementTarget 属性

定义

获取或设置 UIElement,当它打开时相对于它确定 ContextMenu 的位置。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; }
member this.PlacementTarget : System.Windows.UIElement with get, set
Public Property PlacementTarget As UIElement

属性值

ContextMenu 打开时所在位置与之相关的元素。The element relative to which the ContextMenu is positioned when it opens. 默认值为 nullThe default is null.

属性

示例

的目标ContextMenu是其父级。The target of a ContextMenu is its parent. 下面的示例演示如何使用PlacementTarget属性来查找的父级。 ContextMenuThe 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

注解

ContextMenuService FrameworkElement FrameworkContentElement当分配FrameworkElement.ContextMenu给或FrameworkContentElement.ContextMenu属性时,会ContextMenu将此属性的此值更改为拥有或打开时的。 ContextMenuWhen 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. 若要使用不同UIElement的, 请ContextMenuService.PlacementTarget设置属性。To use a different UIElement, set the ContextMenuService.PlacementTarget property.

依赖项属性信息Dependency Property Information

标识符字段Identifier field PlacementTargetProperty
元数据属性设置为trueMetadata properties set to true NoneNone

适用于

另请参阅