dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.84k stars 1.67k forks source link

Erratic Behavior in Button's on Text Change #21890

Open Saleca opened 2 months ago

Saleca commented 2 months ago

Description

When I click a button the color changes to the color of shadow property.

Steps to Reproduce

  1. Create a MAUI project.
  2. Create a Style for Button that has a Shadow property and a VisualState for Normal, Pressed and Released defining BackgroundColor property. (I used same color for Normal and Released to create the Pressed effect)
  3. Create a Button on MainPage.xaml with Clicked event. (I also tried Pressed and Released with the same outcome)
  4. On the MainPage.xaml.cs Clicked event change the Text of the Button.

Expected behavior:

Actual behavior:

On Styles.xaml:

  <Shadow
 x:Key="Shadow" 
 Brush="White"/>

 <Style TargetType="Button">
     <Setter Property="Shadow" Value="{StaticResource Shadow}"/>
     <Setter Property="VisualStateManager.VisualStateGroups">
         <VisualStateGroupList>
             <VisualStateGroup x:Name="CommonStates">
                 <VisualState x:Name="Normal" >
                     <VisualState.Setters>
                         <Setter Property="BackgroundColor" Value="Transparent" />
                     </VisualState.Setters>
                 </VisualState>
                 <VisualState x:Name="Pressed" >
                     <VisualState.Setters>
                         <Setter Property="BackgroundColor" Value="DarkGray" />
                     </VisualState.Setters>
                 </VisualState>
                 <VisualState x:Name="Released" >
                     <VisualState.Setters>
                         <Setter Property="BackgroundColor" Value="Transparent" />
                     </VisualState.Setters>
                 </VisualState>
             </VisualStateGroup>
         </VisualStateGroupList>
     </Setter>
 </Style>

On MainPage.xaml:

    <Button
        x:Name="Btn"
        Text="Press Me"
        Clicked="ButtonClicked"/>

On MainPage.xaml.cs

private void ButtonClicked(object sender, EventArgs e) => Btn.Text = "Pressed";

Link to public reproduction project repository

https://github.com/Saleca/DebugFeatures

Version with bug

8.0.3 GA

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

windows 10.0.17763.0

Did you find any workaround?

Removed Shadow from the Button

Relevant log output

No response

ninachen03 commented 2 months ago

Verified this issue with Visual Studio 17.10.0 Preview 3 (8.0.20 & 8.0.0-rc.2.9530).I can repro this issue on windows machine

Saleca commented 2 months ago

I wanna just add that if the shadow has a AppThemeBinding and at runtime you change the theme of windows it fixes the issue

 <Shadow
 x:Key="Shadow" 
 Brush="{AppThemeBinding Light=Blue, Dark=Red}"/>

Run the app with the Shadow changed, the issue is still present if you press the button, but if you change to Dark mode or Light mode on Windows the issue fixes itself. Probably not a solution but maybe helpfull for who tries to fix the issue.

Saleca commented 2 months ago

sorry i didnt know "close with comment" was a button