我有一个 GridView 绑定到我的 C# 中的数据源,当用户水平滚动时它会加载更多数据:
从 GridView.xaml:
<GridView Grid.Row="1" x:Name="GridViewStories" ItemsPanel="{StaticResource GridViewVerticalTemplate}" IsSwipeEnabled="False" SelectionMode="None" IsItemClickEnabled="True" ItemClick="GridViewStories_ItemClick" IncrementalLoadingTrigger="Edge">
<GridView.ItemContainerTransitions>
<TransitionCollection />
</GridView.ItemContainerTransitions>
<GridView.ItemTemplate>
<DataTemplate>
<Image Source="{Binding SquareImageURL}" Margin="10" Width="240" Height="160" />
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
我希望它在快照视图中表现得像 ListView,这意味着它应该垂直滚动而不是水平滚动。除了这个问题,我已经能够通过 VisualStateManager 改变我需要的一切:
从 GridView.xaml:
<VisualState x:Name="Snapped">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="StackPanelHeader" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="StackPanelHeaderSnapped" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="StackPanelHeaderPortrait" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="GridViewStories" Storyboard.TargetProperty="ItemsPanel">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource GridViewHorizontalTemplate}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
来自 StandardStyles.xaml:
<ItemsPanelTemplate x:Key="GridViewHorizontalTemplate">
<WrapGrid Orientation="Horizontal" HorizontalAlignment="Center" MaximumRowsOrColumns="1" />
</ItemsPanelTemplate>
我不想将 GridView 包装在 Scrollviewer 中,因为这样做会破坏我正在使用的内置增量加载。我意识到我可以只创建一个 ListView 并切换它和 GridView 的可见性,但我宁愿不必绑定到额外的控件并复制其他相关代码。想法?