我有Point.I想在Point附近显示Popup。有没有设置它的属性?我在这里发现了类似的问题,但它们不是我想要的
答案 0 :(得分:4)
这是一个例子。只要在窗口上单击鼠标,就会移动弹出窗口:
<强> XAML:强>
<Window x:Class="WpfApplication60.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="myWindow"
Title="MainWindow" Height="350" Width="525" MouseLeftButtonDown="Window_MouseLeftButtonDown">
<Grid>
<Popup x:Name="myPopup" PlacementTarget="{Binding ElementName=myWindow}" Placement="Relative">
<Label Width="50" Height="20" Background="LightGreen" MouseLeftButtonDown="Label_MouseLeftButtonDown">I am the Popup</Label>
</Popup>
</Grid>
</Window>
代码背后:
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Point current = e.GetPosition(this);
myPopup.HorizontalOffset = current.X;
myPopup.VerticalOffset = current.Y;
myPopup.IsOpen = true;
}