Visual states are not running storyboards within a control template
Posted: 20 Feb 2024, 06:36
Hi, I've run into an issue where I cannot run storyboards on a tab item as I switch their selected state.
This code snippet functions as expected within blend -- the selected tab item turns red when changing visual states.
However, in native noesis the storyboards are not run when changing visual states. Only the first tab item which is selected by default will turn red.
I've gotten around this issue for now by using Triggers.
This code snippet functions as expected within blend -- the selected tab item turns red when changing visual states.
However, in native noesis the storyboards are not run when changing visual states. Only the first tab item which is selected by default will turn red.
Code: Select all
<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid>
<Rectangle x:Name="Rect" Fill="Blue"/>
<ContentPresenter ContentSource="Header"/>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Selected">
<Storyboard Duration="0:0:1">
<ColorAnimation Storyboard.TargetName="Rect" Storyboard.TargetProperty="Fill.(SolidColorBrush.Color)" To="Red"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Unselected"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>