我在页面上显示了一个弹出窗口,我试图获取它的(x,y)坐标,即使弹出窗口在屏幕上可见,我也得到了异常。
private void showPopup_Click(object sender, RoutedEventArgs e)
{
Popup p = new Popup();
StackPanel panel1 = new StackPanel();
// Create some content to show in the popup. Typically you would
// create a user control.
Border border = new Border();
border.BorderBrush = new SolidColorBrush(Colors.Black);
border.BorderThickness = new Thickness(5.0);
panel1.Height = 200;
panel1.Width = 100;
panel1.Background = new SolidColorBrush(Colors.LightGray);
p.Height = 200;
p.Width = 100;
Button button1 = new Button();
button1.Content = "Close";
button1.Margin = new Thickness(5.0);
button1.Click += new RoutedEventHandler(button1_Click);
TextBlock textblock1 = new TextBlock();
textblock1.Text = "The popup control";
textblock1.Margin = new Thickness(5.0);
panel1.Children.Add(textblock1);
panel1.Children.Add(button1);
border.Child = panel1;
// Set the Child property of Popup to the border
// which contains a stackpanel, textblock and button.
p.Child = border;
// Set where the popup will show up on the screen.
p.VerticalOffset = 100;
p.HorizontalOffset = 200;
// Open the popup.
p.IsOpen = true;
}
</弹出>-->