【问题标题】:UWP Position absolute popupUWP 位置绝对弹出窗口
【发布时间】:2018-11-26 08:45:09
【问题描述】:

我有弹出窗口。 单击GridView 中的按钮时,将显示弹出窗口。我为弹出窗口设置了VerticalOffsetHorizontalOffset。 但是我有问题,当我滚动 GridView 弹出窗口不动时。 我可以设置弹出绝对吗?

【问题讨论】:

    标签: .net xaml uwp


    【解决方案1】:

    正如documentation 所说,Offset 属性设置相对于应用程序窗口的位置:

    获取或设置应用程序左侧之间的距离 窗口和弹出窗口的左侧。

    这意味着,该位置设置为相对于窗口的绝对位置,并且在滚动GridView 时不会自动更新。相反,您必须通过观察滚动查看器事件来手动更新它。先用VisualTreeHelperGridView里面找到ScrollView

    public static ScrollViewer FindScrollViewer(DependencyObject d)
    {
        if (d is ScrollViewer) return d as ScrollViewer;
    
        for (int i = 0; i < VisualTreeHelper.GetChildrenCount(d); i++)
        {
            var child = VisualTreeHelper.GetChild(d, i);
    
            var result = FindScrollViewer(child);
            if (result != null) return result;
        }
        return null;
    }
    

    你可以像这样使用这个辅助方法:

    var scrollViewer = FindScrollViewer(MyGridView);
    

    现在附加scrollViewer.ViewChangedscrollViewer.ViewChanging 事件并根据需要更新弹出位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-06
      • 2018-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-05
      相关资源
      最近更新 更多