2011-09-16 2 views
4

xmlから1000個のアイテムがあり、それらをListオブジェクトにロードしました。 Listは、ListBoxにデータバインドされています。このListBoxは水平方向に配置されているため、ユーザーは左右または右から左に項目を移動できます。アイテムの数が巨大なので、私のアプリはおそらくメモリの過剰使用のために終了していました。アイテムを50に減らした場合、それは機能しました。 リストボックスのデータ仮想化が有効になっていません

は、私がこの記事 http://shawnoster.com/blog/post/Improving-ListBox-Performance-in-Silverlight-for-Windows-Phone-7-Data-Virtualization.aspx

、その後、私は何の違いを見ていないのIListを実装する仮想化されたクラスを実装した後、データ仮想

http://blogs.msdn.com/b/ptorr/archive/2010/08/16/virtualizing-data-in-windows-phone-7-silverlight-applications.aspx

に、この記事を見つけました。 UIは既にListboxで仮想化されていると分かっているので、この[](下)は1000回呼び出されていますが、30-40回しか呼び出されないことが予想されます。なぜ仮想化が蹴られていないのですか?

object IList.this[int index] 
{ 
    get 
    { 
     if (index >= cachedItems.Count) 
     { 
      //replenish cache code here 
     } 

     return cachedItems[index]; 
    } 
    set 
    { 
     throw new NotImplementedException(); 
    } 
} 

これは、問題に関連するXAML部分です。これがコードの完全な図を与えることを望みます。 Width=Autoには何か関係がありますが、それ以外の場合は変更できませんかわかりません。

ここ
<ScrollViewer HorizontalScrollBarVisibility="Auto" Margin="0,0,0,0" Width="auto" x:Name="WordsScrollview" Opacity="1" Grid.Row="1" RenderTransformOrigin="0.5,0.5"> 

    <ListBox x:Name="horizontalListBox" Width="auto" Height="Auto" > 

     <ListBox.ItemsPanel> 
      <ItemsPanelTemplate> 
       <StackPanel Orientation="Horizontal"> 
       </StackPanel> 
      </ItemsPanelTemplate> 
     </ListBox.ItemsPanel> 

     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <StackPanel> 
        <TextBlock Width="430" Text="{Binding Word}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" TextAlignment="Center" /> 
        <Image Height="290" HorizontalAlignment="Center" Name="image1" Stretch="Fill" Width="430" Source="{Binding ImageFile}" Margin="10,50,10,0" /> 
       </StackPanel> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 

     <ListBox.Background> 
      <SolidColorBrush /> 
     </ListBox.Background> 

    </ListBox> 

</ScrollViewer> 
+2

UIの仮想化を無効にしますItemsPanelTemplateをStackPanelに水平方向に配置して、リストが実際には仮想化されなくなるようにします。 –

+0

実際には、データ仮想化とUI仮想化は2つの異なるトピックであるため、XAMLが必要です。 –

+0

XAMLを貼り付けただけですが、何らかの理由でトップタグが途切れました。基本的にこの部分は、ScrollViewer Horizo​​ntalScrollBarVisibility = "Auto" Margin = "0,0,0,0" Width = "auto" x:Name = "WordsScrollview" Opacity = "1" Grid.Row = "1" RenderTransformOrigin = "0.5、 0.5 "> – climbon

答えて

3

が最終的にキックするUIの仮想化を引き起こしているXAMLです。次の記事で

 <ListBox x:Name="horizontalListBox" Height="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto" > 

       <ListBox.ItemsPanel> 
        <ItemsPanelTemplate> 
         <VirtualizingStackPanel Orientation="Horizontal"> 

         </VirtualizingStackPanel> 
        </ItemsPanelTemplate> 
       </ListBox.ItemsPanel> 
       <ListBox.ItemTemplate> 
        <DataTemplate> 

          <StackPanel> 
           <TextBlock Width="430" Text="{Binding Word}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" TextAlignment="Center" /> 

           <Image Height="290" HorizontalAlignment="Center" Name="image1" Stretch="Fill" Width="430" Source="{Binding ImageFile}" Margin="10,50,10,0" /> 
           </StackPanel> 

        </DataTemplate> 
       </ListBox.ItemTemplate> 
       <ListBox.Background> 
        <SolidColorBrush /> 
       </ListBox.Background> 
      </ListBox> 
+1

Scrollviewerが問題でしたか? –

+0

私は同じ問題を抱えていて、ScrollViewerのラッピングを取り除き(ScrollViewer.Horizo​​ntalScrollBarVisibility = "Auto"を追加して)、それを修正しました。 –

+4

@DušanKneževićVirtualizingStackPanelの使用に気づく – onmyway133

関連する問題