Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting button IsEnabled to 'true' does not dynamically change background color to match dark/light theme #16538

Closed
babenkovitaliy opened this issue Aug 4, 2023 · 5 comments · Fixed by #17215
Assignees
Labels
area-controls-button Button, ImageButton fixed-in-8.0.0-rc.2.9373 Look for this fix in 8.0.0-rc.2.9373! platform/macOS 🍏 macOS / Mac Catalyst t/bug Something isn't working
Milestone

Comments

@babenkovitaliy
Copy link

Description

I have an issue:

  • When an application has two buttons where one is enabled and one is disabled
  • When the disabled button gets programmatically enabled, it looks fine.
  • However, once the user dynamically changes the theme to light or dark, the button theme doesn't change to the new dark/light mode.

Real life scenario:

  • I have an application that requires a user to sign in, in order to use certain features. By default, some buttons are disabled until a successful authentication completes. By default, the application is in light mode.
  • Once authentication completes, those buttons are enabled. It looks fine.
  • On the top of my application, I have button that will toggle between light and dark mode. Once the user clicks on the button to toggle into dark mode, the newly enabled buttons are still left in light mode style.
Screen.Recording.2023-08-04.at.12.23.29.AM.mov

Steps to Reproduce

  1. Create new MAUI application.
  2. Open MainPage.xaml that was auto generated. We will modify everything between the to this:
    <ContentPage.Resources>
        <x:String x:Key="SwitchToLightString">Switch to Light Mode</x:String>
        <x:String x:Key="SwitchToDarkString">Switch to Dark Mode</x:String>

    </ContentPage.Resources>

    <VerticalStackLayout>
        <Button x:Name="btnSwitchMode"
                Clicked="btnSwitchMode_Clicked"
                Margin="0,2,0,2"
                Text="{AppThemeBinding Dark={StaticResource SwitchToLightString}, Light={StaticResource SwitchToDarkString}}"/>

        <Button x:Name="btnEnableButtonBelow"
                Clicked="btnEnableButtonBelow_Clicked"
                Margin="0,2,0,2"
                Text="Enable Button Below"/>

        <Button x:Name="btnInitiallyDisabledButton"
                IsEnabled="False"
                Margin="0,2,0,2"
                Text="Initially Disabled Button"/>

    </VerticalStackLayout>
  1. Then, we will change everything in the MainPage.xaml.cs file to this:
public partial class MainPage : ContentPage
{
	public MainPage()
	{
		InitializeComponent();

        App.Current.UserAppTheme = AppTheme.Dark;
	}

    void btnSwitchMode_Clicked(System.Object sender, System.EventArgs e)
    {
        if (App.Current.UserAppTheme is AppTheme.Dark)
            App.Current.UserAppTheme = AppTheme.Light;
        else
            App.Current.UserAppTheme = AppTheme.Dark;
    }

    void btnEnableButtonBelow_Clicked(System.Object sender, System.EventArgs e)
    {
        btnInitiallyDisabledButton.IsEnabled = true;
    }
}
  1. Run the application in Debug mode. It will be set at a dark mode (we set that in the constructor)
  2. Click on the middle button to enable to last button. Everything should still look fine.
  3. Click on the top button to change to light mode. Now you will see the issue - the second/middle button and the last button are both enabled. However, they have different styles.

Link to public reproduction project repository

No response

Version with bug

7.0.92

Last version that worked well

7.0.92

Affected platforms

macOS

Affected platform versions

MacOS Ventura 13.4.1

Did you find any workaround?

Do not allow the user to dynamically change the theme. You can allow the user to change the theme, but require the application to be closed and reopened in order for the application theme to update to the requested dark/light theme.

Relevant log output

No response

@babenkovitaliy babenkovitaliy added the t/bug Something isn't working label Aug 4, 2023
@jsuarezruiz jsuarezruiz added platform/macOS 🍏 macOS / Mac Catalyst area-controls-button Button, ImageButton labels Aug 4, 2023
@ghost ghost added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Aug 4, 2023
@babenkovitaliy babenkovitaliy changed the title Setting button IsEnabled to 'true' does not dynamically change background color to match theme Setting button IsEnabled to 'true' does not dynamically change background color to match dark/light theme Aug 4, 2023
@StephaneDelcroix StephaneDelcroix self-assigned this Aug 7, 2023
@babenkovitaliy
Copy link
Author

Some fun facts about this bug:

  • The culprit is in Resources\Styles\Styles.xaml. In the Button VisualStateGroup, there is this line: <VisualState x:Name="Normal" />. The runtime (whatever is powering MAUI/XAML) understands that it should revert to the default setters set in the Styles.xaml file, but it does not seem to understand that the 'TextColor' and 'BackgroundColor' have AppThemeBinding values (which is supposed to make a certain property like 'BackgroundColor' a dynamic value based on the app theme.
  • Related to the bullet point above, I see a slew of other controls in Styles.xaml file that have the same setup (e.g. CheckBox, DatePicker etc.). I have not had a chance to test out if those controls have the same issue, but I would assume that they do.

@StephaneDelcroix
Copy link
Contributor

we lately merged a large change that should affect this, I need to retest on top of main branch

@MartyIX
Copy link
Contributor

MartyIX commented Aug 10, 2023

@StephaneDelcroix Which PR do you have in mind? #13818?

@mattleibow mattleibow added this to the Backlog milestone Aug 11, 2023
@ghost
Copy link

ghost commented Aug 11, 2023

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@StephaneDelcroix
Copy link
Contributor

I can reproduce this, even with the setter specificity changes

StephaneDelcroix added a commit that referenced this issue Sep 5, 2023
Allow having multiple layers of Bindings, useful for e.g.
AppThemeBinding, Style, VSM

- fixes #16538
@samhouts samhouts modified the milestones: Backlog, Under Consideration Sep 5, 2023
StephaneDelcroix added a commit that referenced this issue Sep 14, 2023
Allow having multiple layers of Bindings, useful for e.g.
AppThemeBinding, Style, VSM

- fixes #16538
@samhouts samhouts modified the milestones: Under Consideration, .NET 8 GA Sep 14, 2023
PureWeen pushed a commit that referenced this issue Sep 14, 2023
* [C] Port the specificity concept to Bindings

Allow having multiple layers of Bindings, useful for e.g.
AppThemeBinding, Style, VSM

- fixes #16538

* test for 17354
samhouts pushed a commit that referenced this issue Sep 17, 2023
* Removed references to GraphicsTester.Skia.Tizen from Maui-dev and Maui-vscode sln files. (#17334)

* Enable requesting the full preview size on iOS drag shadow & iOS and Windows Samples (#17282)

* Enable requesting the full preview size on iOS drag shadow

* Add in windows drag and drop sample

* Move itemssource class into main class

---------

Co-authored-by: TJ Lambert (HE/HIM/HIS) <antlambe@microsoft.com>

* Wait for parent to get set before realizing titleview (#17360)

* [create-pull-request] automated change (#17362)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Make the taps work on all platforms (#17325)

* Added integration test for maui blazor maccatalyst codesign verification. (#17331)

* Added integration test for maui blazor maccatalyst codesign verification.

* Created new Codesign class and moved SearchForExpectedEntitlements to it.

* Updated to DotNetCurrent

* [C] Replace value with same specificity (#17365)

We don't have a test for that

-fixes #17357

* Enable Mac Catalyst Controls Device Tests in CI (#17229)

* Enable Mac Catalyst Controls Device Tests in CI

* Disable failing tests

* [C] Port the specificity concept to Bindings (#17215)

* [C] Port the specificity concept to Bindings

Allow having multiple layers of Bindings, useful for e.g.
AppThemeBinding, Style, VSM

- fixes #16538

* test for 17354

* Revert changes to setting context and add tests (#17348)

* Remove macOS as that is not installed by default (#17379)

* Increase timeouts to 4 hours (#17386)

* Bump the aspnetcore group with 7 updates (#17345)

Bumps the aspnetcore group with 7 updates:

| Package | From | To |
| --- | --- | --- |
| [Microsoft.AspNetCore.Authorization](https://github.com/dotnet/aspnetcore) | `7.0.10` | `7.0.11` |
| [Microsoft.AspNetCore.Components.WebView](https://github.com/dotnet/aspnetcore) | `7.0.10` | `7.0.11` |
| [Microsoft.JSInterop](https://github.com/dotnet/aspnetcore) | `7.0.10` | `7.0.11` |
| [Microsoft.AspNetCore.Components.Web](https://github.com/dotnet/aspnetcore) | `7.0.10` | `7.0.11` |
| [Microsoft.AspNetCore.Authentication.Facebook](https://github.com/dotnet/aspnetcore) | `7.0.10` | `7.0.11` |
| [Microsoft.AspNetCore.Authentication.Google](https://github.com/dotnet/aspnetcore) | `7.0.10` | `7.0.11` |
| [Microsoft.AspNetCore.Authentication.MicrosoftAccount](https://github.com/dotnet/aspnetcore) | `7.0.10` | `7.0.11` |


Updates `Microsoft.AspNetCore.Authorization` from 7.0.10 to 7.0.11
- [Release notes](https://github.com/dotnet/aspnetcore/releases)
- [Changelog](https://github.com/dotnet/aspnetcore/blob/main/docs/ReleasePlanning.md)
- [Commits](dotnet/aspnetcore@v7.0.10...v7.0.11)

Updates `Microsoft.AspNetCore.Components.WebView` from 7.0.10 to 7.0.11
- [Release notes](https://github.com/dotnet/aspnetcore/releases)
- [Changelog](https://github.com/dotnet/aspnetcore/blob/main/docs/ReleasePlanning.md)
- [Commits](dotnet/aspnetcore@v7.0.10...v7.0.11)

Updates `Microsoft.JSInterop` from 7.0.10 to 7.0.11
- [Release notes](https://github.com/dotnet/aspnetcore/releases)
- [Changelog](https://github.com/dotnet/aspnetcore/blob/main/docs/ReleasePlanning.md)
- [Commits](dotnet/aspnetcore@v7.0.10...v7.0.11)

Updates `Microsoft.AspNetCore.Components.Web` from 7.0.10 to 7.0.11
- [Release notes](https://github.com/dotnet/aspnetcore/releases)
- [Changelog](https://github.com/dotnet/aspnetcore/blob/main/docs/ReleasePlanning.md)
- [Commits](dotnet/aspnetcore@v7.0.10...v7.0.11)

Updates `Microsoft.AspNetCore.Authentication.Facebook` from 7.0.10 to 7.0.11
- [Release notes](https://github.com/dotnet/aspnetcore/releases)
- [Changelog](https://github.com/dotnet/aspnetcore/blob/main/docs/ReleasePlanning.md)
- [Commits](dotnet/aspnetcore@v7.0.10...v7.0.11)

Updates `Microsoft.AspNetCore.Authentication.Google` from 7.0.10 to 7.0.11
- [Release notes](https://github.com/dotnet/aspnetcore/releases)
- [Changelog](https://github.com/dotnet/aspnetcore/blob/main/docs/ReleasePlanning.md)
- [Commits](dotnet/aspnetcore@v7.0.10...v7.0.11)

Updates `Microsoft.AspNetCore.Authentication.MicrosoftAccount` from 7.0.10 to 7.0.11
- [Release notes](https://github.com/dotnet/aspnetcore/releases)
- [Changelog](https://github.com/dotnet/aspnetcore/blob/main/docs/ReleasePlanning.md)
- [Commits](dotnet/aspnetcore@v7.0.10...v7.0.11)

---
updated-dependencies:
- dependency-name: Microsoft.AspNetCore.Authorization
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: aspnetcore
- dependency-name: Microsoft.AspNetCore.Components.WebView
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: aspnetcore
- dependency-name: Microsoft.JSInterop
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: aspnetcore
- dependency-name: Microsoft.AspNetCore.Components.Web
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: aspnetcore
- dependency-name: Microsoft.AspNetCore.Authentication.Facebook
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: aspnetcore
- dependency-name: Microsoft.AspNetCore.Authentication.Google
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: aspnetcore
- dependency-name: Microsoft.AspNetCore.Authentication.MicrosoftAccount
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: aspnetcore
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* [create-pull-request] automated change (#17388)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* [X] fix CollectionItems enumeration (#17364)

- fixes #17333

* passing test for #16960 (#17397)

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dustin-wojciechowski <dustin.wojciechowski@microsoft.com>
Co-authored-by: TJ Lambert <50846373+tj-devel709@users.noreply.github.com>
Co-authored-by: TJ Lambert (HE/HIM/HIS) <antlambe@microsoft.com>
Co-authored-by: Shane Neuville <shneuvil@microsoft.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: E.Z. Hart <hartez@users.noreply.github.com>
Co-authored-by: Stephane Delcroix <stephane@delcroix.org>
Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@samhouts samhouts added the fixed-in-8.0.0-rc.2.9373 Look for this fix in 8.0.0-rc.2.9373! label Oct 10, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Nov 9, 2023
@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-button Button, ImageButton fixed-in-8.0.0-rc.2.9373 Look for this fix in 8.0.0-rc.2.9373! platform/macOS 🍏 macOS / Mac Catalyst t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants