AutoSuggestBox sugestion lists not closing during scroll in UWP

混江龙づ霸主 提交于 2021-01-29 12:42:05

问题


AutoSuggestBox suggestion list aren't closing during scroll which causes weird UI issue. The issue will look like the one below, which i have taken from the default XAML Controls Gallery application.

A simple AutoSuggestBox i have tested

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

Is there a better way to fix this other than using ScrollViewer.ViewChanged


回答1:


AutoSuggestBox sugestion lists not closing during scroll in UWP

We could not set the Popup IsLightDismissEnabled as true, it will cause the popup could not display the content stable. I check your screenshot, you could set ShouldConstrainToRootBounds for Pupup control to avoid the list go though the bounds.

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;
}


来源:https://stackoverflow.com/questions/58707561/autosuggestbox-sugestion-lists-not-closing-during-scroll-in-uwp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!