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

If you change the theme after running the app, it will not be applied normally. #6876

Closed
dimohy opened this issue May 6, 2022 · 3 comments
Closed
Assignees
Labels
legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor platform/android 🤖 platform/windows 🪟 s/duplicate 2️⃣ This issue or pull request already exists s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@dimohy
Copy link

dimohy commented May 6, 2022

Description

From a project created with a default project template to App.xaml.cs

	public App()
	{
		InitializeComponent();

		Application.Current.UserAppTheme = AppTheme.Light; // or AppTheme.Dark

		MainPage = new AppShell();
	}

If you specify a theme with UserAppTheme, it seems to work well.

| AppTheme.Dark
image

| AppTheme.Light
image

However, if you change 'UserAppTheme' after the app runs, it does not reflect that well.

| Dark
image

| Change theme to 'Light'
image

At first, I suspected that 'AppThemeBinding' was missing in 'Styles.xaml' of the control expressed, but this is not the case. (Of course, there were RadioButton and other things that were missing)

  1. The background color of the page does not respond to the theme. 'Styles.xaml' specifies the background color of the page as 'AppThemeBinding'.
    <Style ApplyToDerivedTypes="True" TargetType="Page">
        <Setter Property="Padding" Value="0" />
        <Setter Property="BackgroundColor" Value="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource Black}}" />
    </Style>
  1. The background color of Shell also does not change depending on the theme. Of course, it depends on the platform, but Android changes and Windows doesn't.

| Android
image

| Windows Machine
image

It looks like a bug to me.

Steps to Reproduce

  1. Create a MAUI project by selecting MAUI App from the project template
  2. Modify 'MainPage.xaml' to change theme by pressing radio button as follows
        <VerticalStackLayout Padding="30" Spacing="25">
            <HorizontalStackLayout
                HorizontalOptions="End"
                IsVisible="true"
                Spacing="8">
                <Label Text="Theme" VerticalTextAlignment="Center" />
                <RadioButton
                    x:Name="lightThemeRadioButton"
                    CheckedChanged="lightThemeRadioButton_CheckedChanged"
                    Content="Light"
                    GroupName="theme"
                    MinimumWidthRequest="80" />
                <RadioButton
                    x:Name="darkThemeRadioButton"
                    CheckedChanged="darkThemeRadioButton_CheckedChanged"
                    Content="Dark"
                    GroupName="theme"
                    MinimumWidthRequest="80" />
            </HorizontalStackLayout>
            ...
  1. Modify 'MainPage.xaml.cs' as follows
...
	public MainPage()
	{
		InitializeComponent();

		var theme = Application.Current.RequestedTheme;
		if (theme is AppTheme.Light)
			lightThemeRadioButton.IsChecked = true;
		else if (theme is AppTheme.Dark)
			darkThemeRadioButton.IsChecked = true;
	}

	private void lightThemeRadioButton_CheckedChanged(object sender, CheckedChangedEventArgs e)
	{
		Application.Current.UserAppTheme = AppTheme.Light;
	}

	private void darkThemeRadioButton_CheckedChanged(object sender, CheckedChangedEventArgs e)
	{
		Application.Current.UserAppTheme = AppTheme.Dark;
	}
...
  1. Press the Theme RadioButton Light or Dark to see if it is working

Version with bug

Release Candidate 2 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows

Affected platform versions

Android 21.0, Windows 10.0.17763.0

Did you find any workaround?

No response

Relevant log output

No response

@dimohy dimohy added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels May 6, 2022
@v-longmin v-longmin added s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage and removed s/needs-verification Indicates that this issue needs initial verification before further triage will happen labels May 6, 2022
@v-longmin
Copy link

Verified repro on 17.3.0 Preview 1.0 [32427.505.main]. Repro with above code.

@Eilon Eilon added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 6, 2022
@Redth Redth self-assigned this May 9, 2022
@Redth Redth added this to the 6.0.300-servicing milestone May 9, 2022
@dimohy
Copy link
Author

dimohy commented May 11, 2022

.NET MAUI RC3 seems to have solved the problem.

However, when the theme is specified when the app is started, it is not reflected in Windows.

Reproduction is as follows.

public partial class App : Application
{
	public App()
	{
		InitializeComponent();

        Application.Current.UserAppTheme = AppTheme.Light;

        MainPage = new AppShell();
	}
}

image

Android works fine.

image

@samhouts
Copy link
Member

Duplicate of #6596

@samhouts samhouts marked this as a duplicate of #6596 May 12, 2022
@samhouts samhouts added the s/duplicate 2️⃣ This issue or pull request already exists label May 12, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jun 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor platform/android 🤖 platform/windows 🪟 s/duplicate 2️⃣ This issue or pull request already exists s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants