AutoSuggestBox的建议区域可以强制只向下扩展吗?

问题描述 投票:0回答:1

使用 AutoSuggestBox,其建议区域似乎在从控件向上或向下扩展之间有所不同。据推测,这是基于控件可用空间的最佳估计。

是否可以确保 AutoSuggestBox 的建议列表只会向下扩展?

xaml winui-3
1个回答
0
投票

以下工作有一个警告:当

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;
    };
}
© www.soinside.com 2019 - 2024. All rights reserved.