2

我有一个 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 的可见性,但我宁愿不必绑定到额外的控件并复制其他相关代码。想法?

4

2 回答 2

0

尝试将以下内容添加到您的GridView

<GridView.ItemsPanel>
    <ItemsPanelTemplate>
        <StackPanel Orientation="Vertical"/>
    </ItemsPanelTemplate>
</GridView.ItemsPanel>
于 2012-12-16T00:31:22.630 回答
0
<GridView Name="display"  ItemsSource="{Binding}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollMode="Enabled" ScrollViewer.VerticalScrollBarVisibility="Visible"  Height="550" Margin="0,0,0,0"  Grid.Row="1" RenderTransformOrigin="0.5,0.5"  SelectionMode="Single" >
    <GridView.RenderTransform>
        <CompositeTransform Rotation="0"/>
    </GridView.RenderTransform>
    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <VariableSizedWrapGrid Orientation="Vertical" />
        </ItemsPanelTemplate>
    </GridView.ItemsPanel>
    <GridView.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Vertical">
                <StackPanel.Background>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FFD3D9DE" Offset="1"/>
                        <GradientStop Color="#FFFAFBFB"/>
                    </LinearGradientBrush>

                </StackPanel.Background>
                <Grid x:Name="grdResultTxtBlock" VerticalAlignment="Center" HorizontalAlignment="Left" Width="500" Height="250" Margin="0,0,0,0">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="55" />
                        <RowDefinition Height="55" />
                        <RowDefinition Height="70"  />
                        <RowDefinition Height="50" />
                    </Grid.RowDefinitions>
                    <Grid Grid.Row="0">
                        <Button  Content="{Binding Call}" Height="40" Style="{StaticResource PnxButtonStyle}"   HorizontalAlignment="Left"
                         Margin="0,10,200,0" x:Name="btnXmit" VerticalAlignment="Top" Width="122" />

                        <TextBlock  x:Name="txtAddress" FontWeight="Bold"  Text="{Binding Address}" Margin="150,0,400,0" HorizontalAlignment="Left"  VerticalAlignment="Center"   Width="200"  />
                        </Grid>
                    </Grid>
              </StackPanel>
            </DataTemplate>
    </GridView.ItemTemplate>
</GridView>
于 2015-11-06T11:58:34.600 回答