封装在ScrollViewer中时,LongListSelector的性能非常糟糕

src*_*091 5 performance xaml longlistselector windows-phone-8

我有一个UserControl需要在顶部和LongListSelector下面包含一堆控件.整体的总高度UserControl可能(并且几乎总是会)超过屏幕高度,在这种情况下,整体UserControl必须是可滚动的.

我目前的设置如下:

<staff:UserContentControl 
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:MyApp.Controls"
    xmlns:staff="clr-namespace:MyApp.Helpers"
    x:Class="MyApp.Controls.RemoteHomePage"

    DataContext="{Binding RelativeSource={RelativeSource Self}}"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}">

    <ScrollViewer>
        <ScrollViewer.Content>
            <StackPanel>
                <TextBlock Txt="Text1" Sign="@" />
                <TextBlock Txt="Text2" Sign="#" />
                <controls:Divider />

                <TextBlock Txt="Text3" Sign="~" />
                <TextBlock Txt="Text4" Sign="~" />
                <controls:TextDivider Text="Divider text" />

                <phone:LongListSelector ItemsSource="{Binding Items}">
                    <phone:LongListSelector.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Title}" />
                        </DataTemplate>
                    </phone:LongListSelector.ItemTemplate>
                </phone:LongListSelector>
            </StackPanel>
        </ScrollViewer.Content>
    </ScrollViewer>
</staff:UserContentControl>
Run Code Online (Sandbox Code Playgroud)

这个解决方案满足了我的需求,但也存在一个很大的问题:LongListSelector当它包含的项目数量相当大时,目前需要花费很多时间来加载.处理300个项目需要8秒钟,在此期间整个UI都被阻止.如果我删除所有内容,但是LongListSelector,如下:

<staff:UserContentControl 
    ...>

    <phone:LongListSelector ItemsSource="{Binding Items}">
        <phone:LongListSelector.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Title}" />
            </DataTemplate>
        </phone:LongListSelector.ItemTemplate>
    </phone:LongListSelector>
</staff:UserContentControl>
Run Code Online (Sandbox Code Playgroud)

然后,LongListSelector即使有大量的物品,几乎立即加载.但显然我需要上面的其他控件,所以问题是我能解决这个问题吗?

(还有相关的问题:我担心LongListSelector里面ScrollViewer可能会导致双滚动或类似的事情,但最终在这方面一切都很好.我不确定是否LongListSelector知道它在其他可滚动控件内或者是否有其他事情发生我不知道.有些解释为什么它工作正常,虽然速度很慢,但我会非常感激.)

dot*_*ten 13

不要使用滚动查看器,因为它会使longlistselector认为它有一个无限高的屏幕可用并呈现其所有项目.而是要解决您的用例,请使用页眉和页脚属性在列表项的上方或下方添加数据.