在 Windows 8.1 商店应用程序中设置 VirtualizingStackPanel.IsVirtualizing

Setting VirtualizingStackPanel.IsVirtualizing in a Windows 8.1 Store App

我在 Windows 8.1 商店应用程序中有一个 XAML 页面。我为 ListView 设置了数据上下文,但我最初将其折叠。我想要做的是在使其可见之前切换 ListView 中某些元素的可见性。但它不会加载它们,除非它变得可见。因此,为了强制它加载项目,我试图将 "IsVirtualizing" 设置为 false 这样我就不必担心它(而且我不介意性能受到影响,因为我不会那么多项目)。但是对于我看的所有例子,我得到的只是

The property "IsVirtualizing" does not have an accessible setter.

不确定这里发生了什么。

这里是去掉其他内容的相关代码。

<common:LayoutAwarePage
    x:Class="FlashMe.DeckView"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:FlashMe"
    xmlns:common="using:FlashMe.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    >


        <ScrollViewer x:Name="deckScrollViewer" Grid.Row="1" VerticalScrollMode="Disabled" HorizontalScrollMode="Enabled" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled" Margin="0,15,0,0">
            <StackPanel x:Name="deckStackPanel" Orientation="Horizontal">
                <Grid Width="100" x:Name="MarginBuffer" />
                <ListView x:Name="cardsListViewDisplay" Visibility="Collapsed" SelectionMode="None" Width="500" ItemsSource="{Binding Path=FlashCardsAsList}" VirtualizingStackPanel.IsVirtualizing="False">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <Border>
                                <StackPanel Orientation="Vertical" Width="490" Height="400" RightTapped="FlashCardRightClicked">
                                    <Grid Width="490" Height="200" Background="Gainsboro">
                                        <TextBlock Text="{Binding Path=Front}"
                                                   Foreground="Black" 
                                                   Style="{StaticResource GroupHeaderTextStyle}"
                                                   Margin="4,0,4,4"
                                                   FontWeight="SemiBold"
                                                   VerticalAlignment="Center"
                                                   HorizontalAlignment="Center"
                                                   TextWrapping="Wrap"
                                                   MaxWidth="410"/>
                                    </Grid>
                                    <Grid Width="500" Height="200" Background="{Binding ElementName=deckStackPanel, Path=DataContext.DeckColorBrush}">
                                        <TextBlock Text="{Binding Path=Back}"
                                                   Foreground="White" 
                                                   Style="{StaticResource GroupHeaderTextStyle}"
                                                   Margin="4,0,0,4"   
                                                   FontWeight="SemiBold"
                                                   VerticalAlignment="Center"
                                                   HorizontalAlignment="Center" 
                                                   TextWrapping="Wrap"
                                                   MaxWidth="410"/>
                                    </Grid>
                                </StackPanel>
                            </Border>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackPanel>
        </ScrollViewer>
</common:LayoutAwarePage>

在 Windows 应用商店中,IsVirtualizing 属性 是只读的。

来自 MSDN VirtualizingStackPanel.IsVirtualizingProperty 页面的备注部分:

VirtualizingStackPanel.IsVirtualizing is an atypical attached property because it does not have a Set accessor, and thus is not really a XAML attached property with a markup usage. Instead, VirtualizingStackPanel.IsVirtualizing functions as a sentinel whereby child elements can query the VirtualizingStackPanel parent, and determine whether virtualization is being used. ...