2012-12-31 30 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內的項目太大(而不是從項目跳轉到項目,它將以小步驟進行),也允許平滑滾動。

希望這可以解決您的問題,問候。

相關問題