2014-10-17 53 views
0

我在ScrollViewer控件下使用Listbox控件。我已經綁定了Listbox控件的項目。Windows Phone 8中列表框控件的項目限制

<ScrollViewer 
    Name="AgreementsSV" > 
    <ListBox 
     x:Name="MyAgr" 
     ItemsSource="{Binding MyAgreementList}" 
     SelectedIndex="-1" > 
     <Custom:Interaction.Triggers> 
      <Custom:EventTrigger EventName="Tap"> 
       <GalaSoft_MvvmLight_Command:EventToCommand 
       x:Name="AgreementTapCommand" 
       Command="{Binding NavigateToDetailsCommand, Mode=OneWay}" 
       CommandParameter="{Binding SelectedItem, ElementName=MyAgr}"/> 
      </Custom:EventTrigger> 
     </Custom:Interaction.Triggers> 
     <ListBox.ItemsPanel> 
      <ItemsPanelTemplate> 
       <StackPanel/> 
      </ItemsPanelTemplate> 
     </ListBox.ItemsPanel> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 

      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 
</ScrollViewer> 

從後端我一次取50個項目,並將它們添加到列表中。 這工作正常,直到我達到列表中的600個項目。之後,應用程序崩潰。我沒有發現任何異常。

所以我想確定是否有任何項目限制列表框控件或ScrollViewer?列表框控件有沒有其他選擇?

獲取列表框數據的代碼。

TotalRecordsExists = responseJson.total; 
foreach (Agreement item in responseJson.rows) 
{ 
    MyAgreementList.Add(item); 
    TotalRecordsFetched++; 
} 
if (TotalRecordsFetched < TotalRecordsExists) 
{ 
    PageNumber++; 
    GetMyAgreements(); 
} 
+0

你爲什麼在scrollviewer裏添加你的列表框?列表框有一個滾動查看器本身。我建議你移除scrollviewer並重試。 – 2014-10-17 07:14:38

+0

也請在您從後端獲取數據的函數中設置一些斷點。後端可能會在600個項目後返回一些錯誤。請確認所有內容都正常運行,直到您將項目添加到集合中並且僅在此之後才發生崩潰。 – 2014-10-17 07:16:08

+0

爲什麼要將ItemsPanel設置爲StackPanel? – 2014-10-17 07:17:01

回答

0

不要將ListBox添加到ScrollViewer中。 ListBox ContentControl有它自己的內置滾動查看器應該很好。

試試這個代碼: -

  <ListBox 
       x:Name="MyAgr" 
       ItemsSource="{Binding MyAgreementList}" 
       SelectedIndex="-1" > 
       <Custom:Interaction.Triggers> 
        <Custom:EventTrigger EventName="Tap"> 
         <GalaSoft_MvvmLight_Command:EventToCommand 
         x:Name="AgreementTapCommand" 
         Command="{Binding NavigateToDetailsCommand, Mode=OneWay}" 
         CommandParameter="{Binding SelectedItem, ElementName=MyAgr}"/> 
        </Custom:EventTrigger> 
       </Custom:Interaction.Triggers> 
       <ListBox.ItemsPanel> 
        <ItemsPanelTemplate> 
         <StackPanel/> 
        </ItemsPanelTemplate> 
       </ListBox.ItemsPanel> 
       <ListBox.ItemTemplate> 
        <DataTemplate> 

        </DataTemplate> 
       </ListBox.ItemTemplate> 
      </ListBox> 

此外,我不認爲有必要爲StackPanel的ItemsPanel在那裏。

0

我覺得你在應用程序中遇到內存不足。不使用堆棧面板,而是使用默認進行數據虛擬化的virtualizedstackpanel。你也可以嘗試使用LongListSelector而不是ListBox。

相關問題