maui icon indicating copy to clipboard operation
maui copied to clipboard

Button BackgroundColor does not change with IsEnabled State on Release to Device Only

Open zslocum opened this issue 3 years ago • 5 comments

Description

After building for release and sideloading the APK onto a device a button which changes IsEnabled state does not have it's background color change with the state even though that is configured and works in an Emulator.

Steps to Reproduce

  1. Start a new MAUI project in Visual Studio using the default template.
  2. Add a button that toggles the state of the default 'Click Me' button that is in the MainPage.xaml: <Button Clicked="OnToggleClicked" Text="Toggle Other Button" />

MainPage.xaml.cs : private void OnToggleClicked(object sender, EventArgs e) { CounterBtn.IsEnabled = !CounterBtn.IsEnabled; }

  1. Run the project in an Android emulator and you will see that the "Click Me" button changes background as expected when the "Toggle Other Button" button is pressed.

  2. Build the project using: dotnet build -c Release -f net6.0-android

  3. Copy the resulting APK to a device and install it.

  4. Run the app and the button does not change background as it did within the emulator but the text color will still change.

Version with bug

6.0.400

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 12

Did you find any workaround?

Use the Background property instead of BackgroundColor and the button color changes as expected. Just need to make sure to use Brush instead of Color as the values.

Relevant log output

No response

zslocum avatar Jul 24 '22 01:07 zslocum

Thank you for your workaround, zslocum

leoderja avatar Jul 27 '22 17:07 leoderja

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost avatar Aug 30 '22 14:08 ghost

This occurs in iOS as well with an .ipa uploaded via testflight.

@zslocum's work around solves for both platforms. Much appreciated.

samuelcourtney avatar Sep 13 '22 19:09 samuelcourtney

I have the same problem (in Android), but in addition, my button is not re-enabled (I can see the foreground color change, but not the background, but users can't click it [usinga Clicked event, not a MVVM Command], which makes it extremely frustrating). Doesn't happen when debugging from VS, but happens when you sideload the published APK.

As a workaround, I'm just changing the colors and adding a guard clause to the event, but this is extremely annoying and I'm wondering what kind of real-life tests have been done before getting MAUI to a "release" state (I seem to be doing workaround after workaround for bugs that are published here as issues for the most extremely basic things).

Not wanting to bash the MAUI devs, of course, it is what it is, but the fact that MAUI was even considered "final" at any point (probably nothing to do with the actual MAUI devs), is flabbergasting to me

javiercampos avatar Oct 25 '22 12:10 javiercampos

Had the same problem today.

I used something like to pass data from one page to the previous one:

await Shell.Current.GoToAsync($"..?UserCredentialsSet={UserCredentialsSet}");

The XAML of that previous page had this in it:

<Button.Triggers>
    <DataTrigger TargetType="Button" Binding="{Binding UserCredentialsSet}" Value="false">
        <Setter Property="IsEnabled" Value="False" />
        <Setter Property="BackgroundColor" Value="Gray" />
    </DataTrigger>
    <DataTrigger TargetType="Button" Binding="{Binding UserCredentialsSet}" Value="true">
        <Setter Property="IsEnabled" Value="True" />
    <Setter Property="BackgroundColor" Value="#512BD4" />
    </DataTrigger>
</Button.Triggers>

On the Android emulator the buttons changed color depending on the status of the user credentials (set or not set), but on my Android device the colors did not change. When I closed the app and restarted the button color was correct, but when I changed the setting of the user credentials the colors stay the same and only changed after restarting the app.

Using the Background property instead of BackgroundColor, as @zslocum suggested, fixed it. With this property I did not have to restart the app on my Android device to make the color of the button change when I set the user credentials to true/false.

Joost1982 avatar Nov 24 '22 23:11 Joost1982

What happens if you disable AOT in release mode?

<RunAOTCompilation>false</RunAOTCompilation>

Might be related to this one: https://github.com/dotnet/maui/issues/11662

mattleibow avatar Dec 08 '22 13:12 mattleibow

Duplicate of #11662

mattleibow avatar Dec 08 '22 14:12 mattleibow