I have my XAML code as below.
<ControlTemplate TargetType="{x:Type local:ThumbnailItem}">
<ContentPresenter>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="FocusedStates">
<VisualState Name="Selected">
<Storyboard>
<ColorAnimation To="Red"
Storyboard.TargetProperty="Background"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</ContentPresenter>
</ControlTemplate>
I want to access the defined VisualStateGroups
from code behind. But the below code VisualStateManager.GetVisualStateGroups
is always returns null.
ContentPresenter myContentPresenter = FindVisualChild<ContentPresenter>(this);
var visualStateGroups = VisualStateManager.GetVisualStateGroups(myContentPresenter);
Is there any good way to achieve it?