Is it possible to use VisualStates in a gridview itemtemplate? I can use VisualStates if I set them via the ItemContainerStyle ControlTemplate but that only gives me access to Items at the same level and including ContentPresenter. What I want to do is change the background colour of a control inside the content presenter. Here’s a simple example that doesn’t seem to be having any effect.
<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>
Pretty sure you can’t. The ItemTemplate base control does not handle any of the mouse/focus events, AFAIK. If you can create a copy of a template for a default control and it does not have defined visual states, you cannot define new ones and have them automatically called. IN this case, the item template is not aware of any mouse/focus/whatever info. Don’t have time to confirm all this, but 99% sure.