问题
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