VisualState Pressed is not working on touch screen
Posted: 02 Jul 2021, 12:59
Hello,
I want to change visual of the button when pressed. It works on mouse click but not on touch on touch screen.
Any idea how to fix this? Is there any alternative approach?
I want to change visual of the button when pressed. It works on mouse click but not on touch on touch screen.
Code: Select all
<ControlTemplate x:Key="testVisualStates" TargetType="{x:Type Button}">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0" To="Pressed" />
<VisualTransition GeneratedDuration="0" From="Pressed" />
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal" />
<VisualState x:Name="MouseOver" />
<VisualState x:Name="Pressed">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="ButtonBrush" Storyboard.TargetProperty="Color">
<EasingColorKeyFrame KeyTime="0" Value="Yellow" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.Background>
<SolidColorBrush x:Name="ButtonBrush" Color="Green"/>
</Grid.Background>
</Grid>
</ControlTemplate>