gpt4 book ai didi

c# - Flyout 或 Popup 以显示附加信息

转载 作者:行者123 更新时间:2023-11-30 16:05:24 26 4
gpt4 key购买 nike

我想在我的应用程序顶部显示带有附加信息的弹出窗口,我的信息是 Listview,其中包含约 500 个项目我都尝试过:

  • flyout 有问题 -> 它内部可能有 scrollViewer,因此我的 ListView 无法正确虚拟化,其他一切正常。这是我的代码:

    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;

那么我应该走哪条路,尝试编辑弹出窗口的模板或通过设置垂直和水平偏移使我的弹出窗口居中?或者有更好的方法来显示弹出窗口,如带有项目列表或其他信息的窗口

最佳答案

默认情况下,Flyout 内部有一个 ScrollViewer。您可以在 FlyoutPresenter styles and templates 找到它的模板。 .您可以通过设置 Flyout.FlyoutPresenterStyle 来编辑它并使用新模板。如果需要的话。

如果你想使用PopupHorizo​​ntalAlignmentVerticalAlignment属性,你需要添加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备注部分,它说:

You position the Popup by setting the HorizontalOffset and VerticalOffset properties. The Popup is offset relative to its immediate parent container.

我认为在使用 Horizo​​ntalAlignment.CenterVerticalAlignment.Center 时,它将 Horizo​​ntalOffsetVerticalOffset 设置为其父宽度和高度的一半。

并且在备注部分,它还说:

Do not use a Popup if a Flyout, MenuFlyout, ToolTip or MessageDialog is more appropriate.

所以我认为在您的情况下使用 Flyout 是更好的方法。

关于c# - Flyout 或 Popup 以显示附加信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33641460/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com