ListBox 虚拟化中的 ListBox

ListBox inside ListBox virtualization

ListBox 有子列表框作为一个项目。虚拟化在父列表框上效果很好,但是,要求是在子列表框上激活虚拟化 + 子列表框不应该有滚动条。可能吗?

设置内层ListBoxHeightMaxHeight属性以及要禁用的ScrollViewer.VerticalScrollBarVisibility附加的属性滚动条。以下示例在 ListBoxes:

中都使用了 UI 虚拟化
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        var outer = Resources["outer"] as CollectionViewSource;
        outer.Source = Enumerable.Range(1, 100);

        var inner = Resources["inner"] as CollectionViewSource;
        inner.Source = Enumerable.Range(1, 100);
    }
}

XAML:

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp2"
        mc:Ignorable="d"
        Title="MainWindow" Height="300" Width="300">
    <Window.Resources>
        <CollectionViewSource x:Key="outer" />
        <CollectionViewSource x:Key="inner" />
    </Window.Resources>
    <Grid>
        <ListBox ItemsSource="{Binding Source={StaticResource outer}}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <ListBox ItemsSource="{Binding Source={StaticResource inner}}" 
                             MaxHeight="100" ScrollViewer.VerticalScrollBarVisibility="Disabled" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Window>