如何在列表框中加载所有项目,而不仅仅是视觉项目

本文关键字:项目 视觉 不仅仅是 加载 列表 | 更新日期: 2023-09-27 17:50:05

如何加载列表框中的所有项目,而不仅仅是显示的项目?基本上,如何关闭Listbox的虚拟化?我试过了,但都没用。

            <ListBox x:Name="listBox1" VirtualizingStackPanel.IsVirtualizing="True" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" Background="Black" BorderThickness="0" IsEnabled="False" ForceCursor="True">
                <ListBox.RenderTransform>
                    <TranslateTransform x:Name="listBoxTransform" />
                </ListBox.RenderTransform>
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel x:Name="wp" IsItemsHost="True" ItemHeight="244" ItemWidth="184" Width="1700">
                        </WrapPanel>                            
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate DataType="{x:Type Image}" x:Name="dtName">
                        <!-- The Image binding -->
                        <Image Width="170" Height="230" Source="{Binding}" Stretch="Fill" />
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ListBox> 

如何在列表框中加载所有项目,而不仅仅是视觉项目

使用此代码(根据您的代码修改)

        <ListBox x:Name="listBox1" VirtualizingStackPanel.IsVirtualizing="False"
                  ScrollViewer.HorizontalScrollBarVisibility="Auto"
                  ScrollViewer.VerticalScrollBarVisibility="Auto"
                  ScrollViewer.CanContentScroll="False"
                  Background="Black" BorderThickness="0" IsEnabled="False"
                  ForceCursor="True">
            <ListBox.RenderTransform>
                <TranslateTransform x:Name="listBoxTransform" />
            </ListBox.RenderTransform>
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel x:Name="wp" IsItemsHost="True" ItemHeight="244" ItemWidth="184" Width="1700">
                    </WrapPanel>                            
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate DataType="{x:Type Image}" x:Name="dtName">
                    <!-- The Image binding -->
                    <Image Width="170" Height="230" Source="{Binding}" Stretch="Fill" />
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ListBox> 

我改变了VirtualizingStackPanel。IsVirtualizing为False(如前一个答案所建议的),并且我添加了ScrollViewer。CanContentScroll="False",这否定了虚拟化,也允许平滑滚动,如果列表框内的项目太大(而不是从一个项目跳到另一个项目,它走一小步)。

希望这能解决你的问题。

<ListBox VirtualizingStackPanel.IsVirtualizing="False" 
                       ItemsSource="{Binding XPath=Team}" 
                       ItemTemplate="{DynamicResource NameDataStyle}"/>

您必须重写ItemsPanel(特别是,提供一个新的ItemsPanelTemplate),因为这是指定/使用VirtualizingStackPanel的地方。

像这样:

<ListBox>
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
</ListBox>