使用分组在Win 8.1 Gridview中启用虚拟化

时间:2014-06-06 19:19:25

标签: gridview windows-8.1 ui-virtualization

我一直在尝试减少包含此gridview的页面的加载时间,根据MS文档http://msdn.microsoft.com/en-US/library/windows/apps/xaml/hh780657.aspx,如果使用分组,则不会进行虚拟化。有谁知道怎么做?

<CollectionViewSource x:Name="serviceViewSource" Source="{Binding PageData}" IsSourceGrouped="True" ItemsPath="Contents" />


<GridView
        x:Name="itemGridView"
        AutomationProperties.AutomationId="ItemsGridView"
        AutomationProperties.Name="Items"
        ScrollViewer.IsHorizontalScrollChainingEnabled="False"
        TabIndex="1"
        Padding="120,0,0,50"
        ItemsSource="{Binding Source={StaticResource serviceViewSource}}"
        SelectionMode="Multiple"
        IsSwipeEnabled="True"
        IsItemClickEnabled="True"
        IsEnabled="{Binding IsGridViewEnabled}"
        CanReorderItems="False" CanDragItems="False" Grid.Row="1" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" ShowsScrollingPlaceholders="True"
        common:GridViewItemClickedCommand.Command="{Binding ItemClickedCommand}" ItemTemplateSelector="{StaticResource gridViewTemplateSelector}"
        >

            <GridView.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"  HorizontalAlignment="Stretch"/>
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>

            <GridView.GroupStyle>
                <GroupStyle HidesIfEmpty="True">
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid x:Name="headerGrid">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="90*"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <Button x:Name="headerButton" Content='{Binding Name}' Background="Transparent" Foreground="AliceBlue" BorderThickness="0" Command="{Binding DataContext.HeaderCommand, ElementName=pageRoot}"

                                       IsRightTapEnabled="False" IsHoldingEnabled="False" IsDoubleTapEnabled="False" CommandParameter="{Binding HeaderIdentifier}" FontFamily="Global User Interface" />
                                <ProgressRing Grid.Column="1" IsActive="{Binding LoadingData}" />
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>

                    <GroupStyle.ContainerStyle>
                        <Style TargetType="GroupItem">

                            <Setter Property="BorderBrush" Value="Transparent"/>
                            <Setter Property="BorderThickness" Value="1"/>

                            <Setter Property="HorizontalAlignment" Value="Stretch"/>
                            <Setter Property="VerticalAlignment" Value="Stretch"/>
                        </Style>
                    </GroupStyle.ContainerStyle>

                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>

                            <VariableSizedWrapGrid Margin="0,0,80,0">

                            </VariableSizedWrapGrid>

                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                </GroupStyle>
            </GridView.GroupStyle>
        </GridView>

1 个答案:

答案 0 :(得分:2)

在Windows 8.1中使用带有默认值的GridView将使用ItemsWrapGrid作为面板,这会为您分组虚拟化。如果您拥有代码,则使用StackPanel将无法虚拟化UI。