使用 AutoSuggestBox,其建议区域似乎在从控件向上或向下扩展之间有所不同。据推测,这是基于控件可用空间的最佳估计。
是否可以确保 AutoSuggestBox 的建议列表只会向下扩展?
以下工作有一个警告:当
Popup
应该向上打开时,列表将反转。
private void AutoSuggestBox_Loaded(object sender, RoutedEventArgs _)
{
if (sender is not AutoSuggestBox autoSuggestBox ||
VisualTreeHelper.GetChild(autoSuggestBox, 0) is not Grid grid ||
grid.Children.FirstOrDefault(gridChild => gridChild is Popup) is not Popup popup ||
(popup.Child as Border)?.Child is not ListView popupListView)
{
return;
}
popup.Opened += (sender, _) =>
{
popupListView.ScrollIntoView(popupListView.Items.FirstOrDefault());
popup.VerticalOffset = autoSuggestBox.ActualHeight;
};
}