Flyout 或 Popup 以显示附加信息
Flyout or Popup to display addition info
我想在我的应用程序顶部显示带有附加信息的弹出窗口,我的信息是 Listview
约 500 个项目我都试过了:
flyout
有问题 -> 它可能内部有 scrollViewer,所以我的列表视图没有正确虚拟化,其他一切正常。有我的代码:
Flyout myFlyout = new Flyout();
myFlyout.Placement = FlyoutPlacementMode.Full;
myFlyout.Content = myListView;
myFlyout.ShowAt(this);
popup
有问题 -> 它不居中,verticalAlignment 不起作用,水平也不行
Popup myPopup = new Popup();
myPopup.Child = myListView;
myPopup.IsOpen = true;
那么我应该走哪条路,尝试编辑弹出窗口的模板或通过设置垂直和水平偏移使我的弹出窗口居中?
或者有更好的方法来显示像 window 这样的弹出窗口,其中包含诸如项目列表或其他
之类的信息
默认情况下,Flyout
里面有一个ScrollViewer
。如果需要,您可以在 FlyoutPresenter styles and templates. You can edit it and use new template by setting Flyout.FlyoutPresenterStyle 属性 找到它的模板。
如果要使用 Popup
的 HorizontalAlignment
和 VerticalAlignment
属性,您需要将 Popup
添加为元素中的子元素视觉树。例如:
Popup myPopup = new Popup();
//MainGrid is the top Grid in the Page
MainGrid.Children.Add(myPopup);
myPopup.HorizontalAlignment = HorizontalAlignment.Center;
myPopup.VerticalAlignment = VerticalAlignment.Center;
myPopup.Child = myListView;
myPopup.IsOpen = true;
但请注意,这实际上不会使 Popup
居中。它使 Popup
的左上角居中。在 Popup class 的 Remarks 部分,它说:
You position the Popup by setting the HorizontalOffset and VerticalOffset properties. The Popup is offset relative to its immediate parent container.
我认为在使用 HorizontalAlignment.Center
和 VerticalAlignment.Center
时,它将 HorizontalOffset
和 VerticalOffset
设置为其父级宽度和高度的一半。
并且在备注部分,它还说:
Do not use a Popup if a Flyout, MenuFlyout, ToolTip or MessageDialog is more appropriate.
所以我认为在你的情况下使用 Flyout
是更好的方法。
我想在我的应用程序顶部显示带有附加信息的弹出窗口,我的信息是 Listview
约 500 个项目我都试过了:
flyout
有问题 -> 它可能内部有 scrollViewer,所以我的列表视图没有正确虚拟化,其他一切正常。有我的代码:Flyout myFlyout = new Flyout(); myFlyout.Placement = FlyoutPlacementMode.Full; myFlyout.Content = myListView; myFlyout.ShowAt(this);
popup
有问题 -> 它不居中,verticalAlignment 不起作用,水平也不行Popup myPopup = new Popup(); myPopup.Child = myListView; myPopup.IsOpen = true;
那么我应该走哪条路,尝试编辑弹出窗口的模板或通过设置垂直和水平偏移使我的弹出窗口居中? 或者有更好的方法来显示像 window 这样的弹出窗口,其中包含诸如项目列表或其他
之类的信息默认情况下,Flyout
里面有一个ScrollViewer
。如果需要,您可以在 FlyoutPresenter styles and templates. You can edit it and use new template by setting Flyout.FlyoutPresenterStyle 属性 找到它的模板。
如果要使用 Popup
的 HorizontalAlignment
和 VerticalAlignment
属性,您需要将 Popup
添加为元素中的子元素视觉树。例如:
Popup myPopup = new Popup();
//MainGrid is the top Grid in the Page
MainGrid.Children.Add(myPopup);
myPopup.HorizontalAlignment = HorizontalAlignment.Center;
myPopup.VerticalAlignment = VerticalAlignment.Center;
myPopup.Child = myListView;
myPopup.IsOpen = true;
但请注意,这实际上不会使 Popup
居中。它使 Popup
的左上角居中。在 Popup class 的 Remarks 部分,它说:
You position the Popup by setting the HorizontalOffset and VerticalOffset properties. The Popup is offset relative to its immediate parent container.
我认为在使用 HorizontalAlignment.Center
和 VerticalAlignment.Center
时,它将 HorizontalOffset
和 VerticalOffset
设置为其父级宽度和高度的一半。
并且在备注部分,它还说:
Do not use a Popup if a Flyout, MenuFlyout, ToolTip or MessageDialog is more appropriate.
所以我认为在你的情况下使用 Flyout
是更好的方法。