Button Pressed VisualState not Reverting
See original GitHub issueDescription
As I understand the documentation of the Button VisualState behaviour here , the Pressed state should be entered when a button is pressed, and then left once the button is no longer pressed.
I have modified the standard maui starter project so that the button goes red if pressed. This does happen, but the button does not revert back to the regular colour once the mouse is released.
Steps to Reproduce
- Create a new Maui app
- Under Styles.xaml replace the Button style (starting line 26) with the following:
<Style TargetType="Button">
<Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource Primary}}" />
<Setter Property="BackgroundColor" Value="{AppThemeBinding Light={StaticResource Primary}, Dark={StaticResource White}}" />
<Setter Property="FontFamily" Value="OpenSansRegular"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="CornerRadius" Value="8"/>
<Setter Property="Padding" Value="14,10"/>
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="{AppThemeBinding Light={StaticResource Primary}, Dark={StaticResource White}}" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Pressed">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Red" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Disabled">
<VisualState.Setters>
<Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource Gray950}, Dark={StaticResource Gray200}}" />
<Setter Property="BackgroundColor" Value="{AppThemeBinding Light={StaticResource Gray200}, Dark={StaticResource Gray600}}" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
The button will now turn red when pressed, but will not revert when no longer pressed. It works as expected on android.
Version with bug
6.0.400 (current)
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
Windows 10 19044.1766
Did you find any workaround?
Nope
Relevant log output
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top Results From Across the Web
VisualStateManager does not revert to original state
According to the code you've posted, it seems you are using VisualStateGroup and VisualStates defined in Windows 8.1.
Read more >Visual states - .NET MAUI
NET MAUI visual state manager can be used to make changes to XAML elements ... or has the mouse cursor hovering over it...
Read more >Xamarin.Forms Visual State Manager
Use the Visual State Manager to make changes to XAML elements based on ... The "Pressed" state becomes active when the Button is...
Read more >Programming for the Internet of Things: Using Windows 10 IoT ...
This group consists of three visual states : Normal , PointerOver , and Pressed . The Normal visual state does not include any...
Read more >Designing a Focused Visual State for Custom Silverlight ...
In this particular example, "Unfocused" is a state without a definition. Switching to the definitionless state has the effect of reverting to the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Still seeing this with VS 17.3.0 non-preview.
With the latest release, you just need to add an empty PointerOver state and this will behave as expected: