There are two approaches.
Option 1
HorizontalOffset VerticalOffset. , . : -
private void Button_Click(object sender, RoutedEventArgs e)
{
Popup popup = new Popup();
Button b = (Button)sender;
GeneralTransform gt = b.TransformToVisual(Application.Current.RootVisual);
Point p = gt.Transform(new Point(0, b.ActualHeight));
popup.HorizontalOffset = p.X;
popup.VerticalOffset = p.Y;
popup.Child = new Border()
{
Child = new TextBlock() { Text = "Hello, World!" },
Background = new SolidColorBrush(Colors.Cyan)
};
}
TrannsformToVisual , , , . , .
2
.
<StackPanel>
<Button Content="Click Me" Click="Button_Click" />
<Popup x:Name="popup" />
<TextBlock Text="This text will be occluded when the popup is open" />
</StackPanel>
: -
private void Button_Click(object sender, RoutedEventArgs e)
{
popup.Child = new Border()
{
Child = new TextBlock() { Text = "Hello, World!" },
Background = new SolidColorBrush(Colors.Cyan)
};
popup.IsOpen = !popup.IsOpen;
}
Popup , StackPanel, . , .