我有2级的深度集合,我把它渲染成像Header,Child Item一样的东西。如何进一步优化Windows Store应用程序?
粗略地说,我的代码看起来是这样的:
<ScrollViewer>
<ItemsControl IsEnabled="{Binding Path=IsEnabled}"
ItemsSource="{Binding Path=HeaderViewModels, Mode=OneTime}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemsTemplate>
<DataTemplate>
<StackPanel Visibility="{Binding Path=ShouldShow, Converter={StaticResource SomeConverter}}">
<TextBlock Text="{Binding Path=Description, Mode=OneTime}" />
<ItemsControl ItemsPanel="{StaticResource WinRTXAMLWrapPanel}"
ItemsSource="{Binding Path=ChildViewModels, Mode=OneTime}">
<i:Interaction.Behaviors>
<SomeClass:AdjustSizeBehavior SizeFromParentMode="Height" />
</i:Interaction.Behaviors>
<ItemsControl.ItemsTemplate>
<DataTemplate>
<ContentControl>
<i:Interaction.Behaviors>
<SomeClass:IsEnabledBehavior />
<SomeClass:PointerPressBehavior />
<SomeClass:PointerLeaveBehavior />
</i:Interaction.Behaviors>
<StackPanel>
<TextBlock Text="X">
<i:Interaction.Behaviors>
<SomeClass:SetXMarkColor />
</i:Interaction.Behaviors>
</TextBlock>
<TextBlock Text="{Binding Path=Description, Mode=OneTime}" />
</StackPanel>
</ContentControl>
</DataTemplate>
</ItemsControl.ItemsTemplate>
</ItemsControl>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemsTemplate>
</ItemsControl>
</ScrollViewer>
冷落的造型,但其相当多的背景下,利润,字体大小等。此外,你可以看到我使用大量的绑定和行为。
我已经做了大部分我能想到的优化。删除了不必要的UI元素(例如用于“背景”的矩形),使用StackPanel而不是Grid,将列/高度设置为静态而不是自动。基本上做什么,我可以在此链接:Twelve ways to improve wpf performance和Best practices for Windows Store Apps
随着我也做了优化,其实我已经减少了10头+ 8的孩子每个(共80个)的加载时间,从1.8秒到大约0.5毫秒 - 0.6毫秒。
但是,我希望它达到小于0.5毫秒,所以它就像'即时'。
有什么我可以做的,以提高性能?
谢谢!
使用一个分析器,看看哪些东西仍然需要花费时间并将精力集中在那里。 –
谢谢,是的,为了优化它,我使用了VS 2013 profiler和Windows Performance Recorder。注意到大部分处理都是关于UI元素的,所以在那里努力减少它,但现在我正在寻找其他可能性。 – Water