Xaml 使用VisualStateManager更改ItemsPanelTemplate将禁用滚动条

Xaml 使用VisualStateManager更改ItemsPanelTemplate将禁用滚动条,xaml,gridview,scrollbar,orientation,itemspaneltemplate,Xaml,Gridview,Scrollbar,Orientation,Itemspaneltemplate,我有一个GridView,其中有一个ItemPanel,如下所示: <ItemsPanelTemplate x:Key="PanelTemplateLandscape"> <WrapGrid Orientation="Vertical" /> </ItemsPanelTemplate> <ItemsPanelTemplate x:Key="PanelTemplatePortrait"> <WrapGrid Orientati

我有一个GridView,其中有一个ItemPanel,如下所示:

<ItemsPanelTemplate x:Key="PanelTemplateLandscape">
    <WrapGrid Orientation="Vertical" />
</ItemsPanelTemplate>
<ItemsPanelTemplate x:Key="PanelTemplatePortrait">
    <WrapGrid Orientation="Horizontal" />
</ItemsPanelTemplate>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="DataGrid" Storyboard.TargetProperty="ItemsPanel">
    <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PanelTemplatePortrait}"/>
</ObjectAnimationUsingKeyFrames>

现在,如果应用程序正在将模式更改为“快照”,我想更改此WrapGrid的方向。一种方法是创建第二个ItemsPanelTemplate,如下所示:

<ItemsPanelTemplate x:Key="PanelTemplateLandscape">
    <WrapGrid Orientation="Vertical" />
</ItemsPanelTemplate>
<ItemsPanelTemplate x:Key="PanelTemplatePortrait">
    <WrapGrid Orientation="Horizontal" />
</ItemsPanelTemplate>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="DataGrid" Storyboard.TargetProperty="ItemsPanel">
    <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PanelTemplatePortrait}"/>
</ObjectAnimationUsingKeyFrames>

然后使用VisualStateManager和VisualState“快照”更改ItemsPanel模板,如下所示:

<ItemsPanelTemplate x:Key="PanelTemplateLandscape">
    <WrapGrid Orientation="Vertical" />
</ItemsPanelTemplate>
<ItemsPanelTemplate x:Key="PanelTemplatePortrait">
    <WrapGrid Orientation="Horizontal" />
</ItemsPanelTemplate>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="DataGrid" Storyboard.TargetProperty="ItemsPanel">
    <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PanelTemplatePortrait}"/>
</ObjectAnimationUsingKeyFrames>

为完整起见,以下是GridView标记:

<GridView x:Name="DataGrid" Grid.Row="1" ItemTemplate="{StaticResource Standard250x250ItemTemplate}" ItemsPanel="{StaticResource PanelTemplateLandscape}"
    ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"
    ScrollViewer.HorizontalScrollMode="Auto" ScrollViewer.VerticalScrollMode="Auto">
</GridView>

然后,我在GridView中填充了100个项目,在启动时,它看起来不错,并且有一个可以使用的水平滚动条

现在,如果我向左“捕捉”,方向会改变,现在有一个可以使用的垂直滚动条

到目前为止一切如期

但是如果我现在回到FullScreen模式,方向会正确更改,但是horizonzal滚动条是可见的,但不可用。同样,如果我切换回快照视图,滚动条是可见的,但不可用

在运行时更改模板是否存在已知问题?有办法解决这个问题吗?使用VisualStateManager更改模板是否错误


感谢您的帮助

让您知道,根据Microsoft的说法,您应该使用两个不同的GridView,然后在方向更改时显示一个,隐藏另一个,反之亦然。我也有同样的问题。这将是伟大的,如果有另一种解决方案,可以保存自动滚动位置。