2012-12-31 33 views
1

如何加载列表框中的所有项目而不是仅显示那些项目?基本上,你如何关闭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> 
+0

你确实有VirtualizingStackPanel.IsVirtualizing =“False”?你怎么知道他们没有加载?尝试取出RenderTransform。可能你的渲染滞后不是负载滞后。 – Paparazzi

回答

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

哦,聪明 - 除了显而易见的True => False错字,这可能会奏效......并不知道这是一个附属的属性。 – JerKimball

+0

这似乎并不奏效。我已经更新了我正在尝试工作的源代码的问题。谢谢 – user1585542

+0

@ user1585542,正如JerKimball评论的那样,设置VirtualizingStackPanel.IsVirtualizing =“False” – Ramin

0

你必须重写ItemsPanel(具体地,提供了一个新的ItemsPanelTemplate),因为这是被指定的VirtualizingStackPanel其中/使用。

事情是这样的:

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

使用此代码(从你的修改)

 <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内的项目太大(而不是从项目跳转到项目,它将以小步骤进行),也允许平滑滚动。

希望这可以解决您的问题,问候。

相关问题