如何优化windows phone嵌套列表框?

时间:2014-06-15 09:05:25

标签: windows-phone-8 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; }
}

这是嵌套的列表框

 <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)设备中没问题,我该如何优化是什么?

如果我删除了列表框并在代码后面创建了控件,那么性能会更好吗?

2 个答案:

答案 0 :(得分:1)

如果您不需要滚动(您有ScrollViewer.VerticalScrollBarVisibility="Disabled"),请尝试使用ItemsControl,它应该表现得更好。

答案 1 :(得分:0)

对您的内部列表框使用LongListSelector作为外部Listbox和ItemsControl。因为LongListSelector比ListBox更优化,因为你不能使用嵌套的longlistselector导致滚动和虚拟化问题