Popup.PlacementTarget 属性

定义

获取或设置当打开 Popup 控件时该控件相对于其放置的元素。Gets or sets the element relative to which the Popup 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

属性值

作为 UIElement 控件的逻辑父级的 PopupThe UIElement that is the logical parent of the Popup control. 默认值为 nullThe default is null.

属性

示例

下面的示例创建一个Popup , 它是的子Canvas, 并将设置PlacementTargetellipse1, 因此, popup 是相对于的EllipseThe following example creates a Popup that is the child of a Canvas, and sets PlacementTarget to ellipse1, so the popup is relative to the Ellipse.

<Canvas Margin="5" Background="Red" Width="200" Height="150" >

  <Ellipse Name="ellipse1"
           Canvas.Top="60" Canvas.Left="50"
           Height="85" Width="60" 
           Fill="Black"/>

  <Popup IsOpen="True" PlacementTarget="{Binding ElementName=ellipse1}">
    <TextBlock Background="LightBlue" FontSize="18">This is a Popup</TextBlock>
  </Popup>
</Canvas>

注解

可以PlacementTarget通过设置、 Placement PlacementRectangle、 、HorizontalOffsetVerticalOffset属性来定位 popup。You can position a popup by setting the PlacementTarget, PlacementRectangle, Placement, HorizontalOffset, and VerticalOffset properties. 有关详细信息,请参阅 Popup 放置行为For more information, see Popup Placement Behavior.

依赖项属性信息Dependency Property Information

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

适用于

另请参阅