2014-06-15 43 views
0

這裏是我的數據源類型如何優化windows phone的嵌套列表框?

public class Part 
{ 
    public int PartNumber { get; set; } 
    public string ar_PartNumber { get; set; } 
    public List<PartSuras> PartSuras { get; set; } 
    public int PageNumber { get; set; } 
    public string ar_PageNumber { get; set; } 

} 

public class PartSuras 
{ 
    public int SuraID { get; set; } 
    public string ar_SuraID { get; set; } 

    public string SuraTitle { get; set; } 
    public string SuraTitleEn { get; set; } 
    public int StartVerseID { get; set; } 
    public int PageNumber { get; set; } 
    public string ar_PageNumber { get; set; } 
} 

,這裏是嵌套listboxs

<ListBox Loaded="list_Index_Loaded" Name="list_Index" HorizontalAlignment="Stretch" Margin="-12,-40,-12,0" VerticalAlignment="Top" ScrollViewer.VerticalScrollBarVisibility="Disabled"> 
        <ListBox.ItemTemplate > 
         <DataTemplate> 
          <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Top"> 
           <Button HorizontalAlignment="Stretch" Width="480" BorderBrush="#FFCADBBD" Margin="0,-12" BorderThickness="0,0,0,2" Background="#FFD2BC70" Foreground="Black" Name="bt_part" Tag="{Binding PageNumber}" Tap="bt_part_Tap" > 
            <TextBlock HorizontalAlignment="Stretch" TextAlignment="Center"> 
            <Run Text="الجزء "></Run> 
            <Run Text="{Binding ar_PartNumber}"></Run> 
            </TextBlock> 
           </Button> 
           <ListBox Name="list_sura" ItemsSource="{Binding PartSuras}" ScrollViewer.VerticalScrollBarVisibility="Disabled"> 
            <ListBox.ItemTemplate> 
             <DataTemplate> 
              <Button HorizontalAlignment="Stretch" Width="480" Margin="0,-12" BorderThickness="0,0,0,2" Background="#FFE5DCAA" Foreground="Black" Name="bt_part" Tag="{Binding PageNumber}" Tap="bt_part_Tap" > 
               <Grid Width="430" HorizontalAlignment="Stretch"> 
                <Grid.ColumnDefinitions> 
                 <ColumnDefinition></ColumnDefinition> 
                 <ColumnDefinition></ColumnDefinition> 
                </Grid.ColumnDefinitions> 
                <TextBlock Grid.Column="0" HorizontalAlignment="Stretch" TextAlignment="Left"> 
                <Run Text="{Binding ar_SuraID}"></Run> 
                <Run Text="-"></Run> 
                <Run Text="{Binding SuraTitle}"></Run> 
                </TextBlock> 
                <TextBlock Grid.Column="1" HorizontalAlignment="Stretch" TextAlignment="Right" Text="{Binding ar_PageNumber}"></TextBlock> 
               </Grid> 

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

這是一種緩慢的,它需要近3秒,只建-i meseured構建的時間列表框數據源和它是好的 - 在Lumia 920(1 GB RAM)設備中,我如何優化?

如果我刪除了列表框並在代碼後面創建了控件,性能會更好嗎?

+0

您的數據(記錄數)有多少? –

+0

嘗試將第一個ListBox DataTemplage中的StackPanel替換爲Grid。並嘗試設置第一個列表框的高度/寬度 –

+0

項目數量是30個主要項目和114個孩子 –

回答

1

如果您不需要滾動(您有ScrollViewer.VerticalScrollBarVisibility="Disabled"),請嘗試使用ItemsControl代替,它應該表現更好。

+0

謝謝,這減少了一秒的時間,這是3秒鐘之前 –

0

將LongListSelector用於您的內部Listbox的外部Listbox和ItemsControl。由於LongListSelector比ListBox更優化,因爲您無法使用導致滾動和虛擬化問題的嵌套longlistselector