question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Button Pressed VisualState not Reverting

See original GitHub issue

Description

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

  1. Create a new Maui app
  2. 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:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
nCastle1commented, Aug 19, 2022

Still seeing this with VS 17.3.0 non-preview.

0reactions
hartezcommented, Dec 3, 2022

With the latest release, you just need to add an empty PointerOver state and this will behave as expected:

<Style TargetType="Button">
	<!-- ... setters ... -->
		<VisualStateGroupList>
			<VisualStateGroup x:Name="CommonStates">
				
				<!-- ... other states -->
				
				<VisualState x:Name="Pressed">
					<VisualState.Setters>
						<Setter Property="BackgroundColor" Value="Red" />
					</VisualState.Setters>
				</VisualState>

				<VisualState x:Name="PointerOver" />
				
			</VisualStateGroup>
		</VisualStateGroupList>
	</Setter>
</Style>
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found