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.83k stars 1.67k forks source link

Changing ImageButton source causes flicker #21122

Open joel-heath opened 3 months ago

joel-heath commented 3 months ago

Description

Specifically with Background="Transparent" set, which both removes the background colour but also removes the hover and click effects. Easier to see (and possibly seems to occur more) with a lower MaximumHeightRequest set (eg 100).

Very similar to an old issue, though now specifically with ImageButton. https://github.com/dotnet/maui/issues/6962

Full modifications to default project:

MainPage.xaml

<ImageButton
    x:Name="CounterBtn"
    Source="dotnet_bot.png"
    Background="Transparent"
    MaximumHeightRequest="100"
    SemanticProperties.Hint="Counts the number of times you click"
    Clicked="OnCounterClicked"
    HorizontalOptions="Fill" />

MainPage.xaml.cs

private void OnCounterClicked(object sender, EventArgs e)
{
    CounterBtn.Source = "dotnet_bot.png";
}

Steps to Reproduce

  1. Create a File > New .NET MAUI App
  2. Change the default Button ("CounterBtn") to an ImageButton. Remove the Text attribute
  3. Set Source="dotnet_bot.png", and Background="Transparent"
  4. Optionally set MaximumHeightRequest="100"
  5. In OnCounterClicked(...) remove all code and add CounterBtn.Source = "dotnet_bot.png";
  6. Click the button (may take multiple attempts) and observe a very fast flicker when the source is changed Expected outcome: Image changes, no flicker Actual outcome: Image disappears for a fractional amount of time, then new image appears

Demonstration: https://github.com/dotnet/maui/assets/22117135/85ba4dcc-42db-4a40-b12e-12cf73a541e6

Link to public reproduction project repository

No response

Version with bug

8.0.6 SR1

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

No response

Did you find any workaround?

No response

Relevant log output

No response

XamlTest commented 2 months ago

Verified this on VS 17.10.0 Preview 2.0(8.0.14). Repro on Windows 11 and MacCatalyst, not repro on Android 14.0-API34 and iOS 17.2 with below Project: 21122.zip