C# 如何加载列表框中的所有项目,而不仅仅是可视项目
如何加载列表框中的所有项目,而不是仅加载显示的项目?基本上,如何关闭列表框的虚拟化?我试过了,但没有成功C# 如何加载列表框中的所有项目,而不仅仅是可视项目,c#,wpf,listbox,virtualization,C#,Wpf,Listbox,Virtualization,如何加载列表框中的所有项目,而不是仅加载显示的项目?基本上,如何关闭列表框的虚拟化?我试过了,但没有成功 <ListBox x:Name="listBox1" VirtualizingStackPanel.IsVirtualizing="True" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" Background="
<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>
您必须覆盖
ItemsPanel
(特别是,提供一个新的ItemsPanelTemplate
),因为这是指定/使用虚拟化StackPanel
的地方
大概是这样的:
<ListBox>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
使用此代码(根据您的代码修改)
我将virtualzingstackpanel.isvirtualization更改为False(如前一个答案中所建议的),并添加了ScrollViewer.CanContentScroll=“False”,它否定了虚拟化,并且在列表框中的项目太大时允许平滑滚动(不是从一个项目跳到另一个项目,而是通过小步进行)
希望这能解决你的问题,亲爱的。哦,聪明-除了明显的True=>False打字错误之外,这可能会起作用……我不知道这是一个附加属性。这似乎不起作用。我已经更新了我的问题的源代码,我正试图得到工作。Thanks@user1585542,正如JerKimball评论的那样,设置virtualizangstackpanel.isvirtualization=“False”您确实有virtualizangstackpanel.isvirtualization=“False”?你怎么知道他们没有装货?尝试取出RenderTransform。可能存在渲染延迟,而不是加载延迟。
<ListBox>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</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>