当我像这样添加Popup到我的XAML时
<Grid>
...other controls
<Popup x:Name="popup" Width="200" Height="200" >
</Popup>
</Grid>
即使我没有切换IsOpen = true(但是空格是空白的,因此没有弹出窗口可见),它就像弹出窗口一样;
然而,当我从这样的代码(添加一个弹出窗口)做同样的事情时,它会像它应该的那样工作,它不会干扰任何控件(即移动它们)并且它会按预期弹出顶部其他控件。
Popup p = new Popup();
// 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(0);
StackPanel panel1 = new StackPanel();
panel1.Background = new SolidColorBrush(Colors.);
Button button1 = new Button();
button1.Content = "Close";
button1.Margin = new Thickness(5.0);
button1.Click += new RoutedEventHandler(Feedback_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 = 400;
p.HorizontalOffset = 150;
// Open the popup.
p.IsOpen = true;
有谁知道如何在XAML中完成同样的事情?
答案 0 :(得分:0)
使用Popup
有两种方法。它可以是叠加控件或它可以在布局中定义(或添加到树中),它将占用空间,就像标准控件一样。
要有一个叠加弹出窗口,但要避免在代码隐藏中定义布局,但仍然使用两种技术:
1)将弹出内容定义为单独的用户控件。您的Feedback_Click
等事件处理程序现在将在UserControl
var p = new Popup { Child = new MyControl() };
p.IsOpen = true;
2)仅在ResourceDictionary
的xaml中定义弹出内容。