【问题标题】:AutoSuggestBox sugestion lists not closing during scroll in UWP在 UWP 中滚动期间 AutoSuggestBox 建议列表未关闭
【发布时间】:2019-11-05 18:23:39
【问题描述】:

AutoSuggestBox 建议列表在滚动期间没有关闭,这会导致奇怪的 UI 问题。该问题类似于以下问题,我从默认的 XAML 控件库 应用程序中获取。

一个简单的AutoSuggestBox我测试过

<AutoSuggestBox TextChanged="AutoSuggestBox_TextChanged" Width="300" />

除了使用 ScrollViewer.ViewChanged

,还有没有更好的方法来解决这个问题

【问题讨论】:

    标签: uwp uwp-xaml


    【解决方案1】:

    AutoSuggestBox 建议列表在 UWP 中滚动期间未关闭

    我们无法将Popup IsLightDismissEnabled 设置为true,这将导致popup 无法稳定显示内容。我检查了您的屏幕截图,您可以将ShouldConstrainToRootBounds 设置为Pupup 控件以避免列表超出范围。

    private void AutoSuggestBox_Loaded(object sender, RoutedEventArgs e)
    {
        var popup = MyFindGridViewChildByName(sender as AutoSuggestBox, "SuggestionsPopup") as Popup;
        popup.ShouldConstrainToRootBounds = true;
    }
    public static DependencyObject MyFindGridViewChildByName(DependencyObject parant, string ControlName)
    {
        int count = VisualTreeHelper.GetChildrenCount(parant);
    
        for (int i = 0; i < count; i++)
        {
            var MyChild = VisualTreeHelper.GetChild(parant, i);
            if (MyChild is FrameworkElement && ((FrameworkElement)MyChild).Name == ControlName)
                return MyChild;
    
            var FindResult = MyFindGridViewChildByName(MyChild, ControlName);
            if (FindResult != null)
                return FindResult;
        }
    
        return null;
    }
    

    【讨论】:

    • 我测试了你的代码。 ShouldConstrainToRootBounds 它有助于将弹出窗口限制在窗口内,而不是在标题内。有没有办法限制标题内的界限?
    • 弹窗将跟随AutoSuggestBox,如果AutoSuggestBox滚动显示空气并且弹窗将滚动到,它无法固定在标题下方。这是设计使然。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-02
    • 1970-01-01
    • 2017-11-24
    • 2017-07-27
    • 2019-10-06
    • 2010-09-15
    • 1970-01-01
    相关资源
    最近更新 更多