listbox优化攻略(持续更新中)

  这个做新闻,资讯几乎必不可少的控件,我总结如下:

1.关于模版优化:(节选自:http://www.cnblogs.com/zjfeiye/archive/2011/07/15/2107112.html)

1)取消Grid布局,改用Canvas,将嵌套结构尽量拉平,精简复杂度

2)取消对单个Item的手势和右键菜单监听,在ListBox外围放置统一的监听

2.尽量避免listbox和listbox,itemscontrol,longlistselector等控件相互嵌套。

item多了,容易导致性能下降,或者崩溃,用过的朋友很容易发觉,为节约大家时间,这里不再详述。

 3.注意下面的一段实践优化,外面的代码内存占用会到100+M,而没注释掉的代码,内存会在30+M前后,是不足以破坏虚拟化的。

关于内存测试,传送门在这:http://www.cnblogs.com/hebeiDGL/p/3410575.html

   <!--<ScrollViewer Grid.Row="1" Margin="12,0,12,0">-->
        <ListBox Grid.Row="1" x:Name="ic" VirtualizingStackPanel.VirtualizationMode="Recycling">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid Background="#f0f0f0" Margin="20">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="50"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="{Binding name}" Foreground="SkyBlue" Margin="10"></TextBlock>
                        <TextBlock Grid.Column="1" Foreground="#454545" Margin="10"  Text="{Binding time}" TextAlignment="Right"/>
                        <TextBlock Grid.Row="1" Grid.ColumnSpan="2" Margin="10,0,10,10" Foreground="#4c4c4c" TextWrapping="Wrap" Text="{Binding content}" FontSize="23"/>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <!--</ItemsControl.ItemTemplate>
            </ItemsControl>-->
        <!--</ScrollViewer>-->

 注意:

 listbox:是把后端虚拟化也封装进去了,virtualstackpanel是把封装的开启,stackpanel是不用封装的,
 itemcontrol的话,只写virtualstackpanel,后端没有对应的虚拟化方法.所以要自己封装。 

posted on 2014-04-14 15:14  鸣动我心  阅读(301)  评论(0编辑  收藏  举报