Popup
不承载自己内的孩子。 Popup
的子女托管在PopupRoot
内。你可以在Live Visual Tree
看到它。
你可以看到下面的代码:
TextBlock text = new TextBlock();
text.Text = "Hello";
TextBlock text2 = new TextBlock();
text2.Text = "Hello world";
var objPopup = new Popup()
{
Child = text,
IsOpen = true
};
var objPopup2 = new Popup()
{
Child = text2,
IsOpen = true
};
从图片中,可以看到Button
在RootScrollViewer
和Popup
的孩子们将在PopupRoot
当Popup
显示被展示。
如果要列举所有当前显示的弹出窗口,你可以添加Popup
你可以使用foreach
把所有的Popup
的collection.That一种解决方法,那么你可以使用Popup.IsOpen
知道是否显示在弹出窗口。
例如:
public ObservableCollection<Popup> popups;
public MainPage()
{
this.InitializeComponent();
TextBlock text = new TextBlock();
text.Text = "Hello";
TextBlock text2 = new TextBlock();
text2.Text = "Hello world";
var objPopup = new Popup()
{
Child = text,
IsOpen = true
};
var objPopup2 = new Popup()
{
Child = text2,
IsOpen = true
};
objPopup.HorizontalOffset = 100;
objPopup2.HorizontalOffset = 600;
popups = new ObservableCollection<Popup>();
popups.Add(objPopup);
popups.Add(objPopup);
foreach (var item in popups)
{
if (item.IsOpen == false)
{
item.IsOpen = true;
}
}
}