是否可以在 gridview 项目模板中使用 VisualStates?如果我通过 ItemContainerStyle ControlTemplate 设置它们,我可以使用 VisualStates,但这只能让我访问同一级别的项目,包括 ContentPresenter。我想要做的是更改内容演示器内控件的背景颜色。这是一个似乎没有任何效果的简单示例。
<GridView x:Name="ItemsGrid" ItemContainerStyle="{StaticResource StyleWhereVisualStatesWork}">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid Orientation="Horizontal"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.ItemTemplate> //This Is Where I Can't Get Visual States To Work
<DataTemplate>
<Grid x:Name="ContainerGrid">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="PointerOver">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="TestBackgroundGrid">
<DiscreteColorKeyFrame KeyTime="0" Value="{StaticResource SomeBrush}"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid x:Name="TestBackgroundGrid" Height="60" Width=60" Background="{StaticResource SomeStandardColourBrush}">
</Grid>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>