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

AppThemeBinding doesn't work on .NET7 #13627

Closed
BlyZeYT opened this issue Mar 1, 2023 · 8 comments
Closed

AppThemeBinding doesn't work on .NET7 #13627

BlyZeYT opened this issue Mar 1, 2023 · 8 comments
Labels
area-theme Themes, theming i/regression This issue described a confirmed regression on a currently supported version platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working

Comments

@BlyZeYT
Copy link

BlyZeYT commented Mar 1, 2023

Description

When I use AppThemeBinding in .NET7 the Theme just not changes when I change between light and dark theme. I copied the exact same project in .NET6 and everything works just fine.

Steps to Reproduce

  1. Create the sample .NET Maui project and set any color with an AppThemeBinding.
  2. Start the app and see how it doesn't change when switching themes.

Expected outcome: Switches between the 2 themes
Actual outcome: It doesn't switch anything

Link to public reproduction project repository

The template project

Version with bug

7.0 (current)

Last version that worked well

6.0.424

Affected platforms

Android, I was not able test on other platforms

Affected platform versions

Android 12

Did you find any workaround?

No workaround found.

I could use Dynamic Resource but than the AppThemeBinding is useless.

Relevant log output

No response

@BlyZeYT BlyZeYT added the t/bug Something isn't working label Mar 1, 2023
@samhouts samhouts added platform/android 🤖 i/regression This issue described a confirmed regression on a currently supported version area-theme Themes, theming labels Mar 1, 2023
@jfversluis jfversluis added the s/needs-repro Attach a solution or code which reproduces the issue label Mar 2, 2023
@ghost
Copy link

ghost commented Mar 2, 2023

Hi @BlyZeYT. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@jfversluis
Copy link
Member

Could you elaborate a bit more about "set any color with an AppThemeBinding."?

How are you doing that exactly? On what element?

I guess in this case we might not need a full-blown GitHub repo to show it, but at least please give some relevant concrete code that we can try to reproduce this issue.

@Cybrosys
Copy link

Cybrosys commented Mar 2, 2023

Perhaps related to:
#11299
and
#13619

There seems to be several issues related to DynamicResource bindings, even I created one when used with MCT StatusBarBehavior, but it's in the MCT repo:
CommunityToolkit/Maui#1056

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue labels Mar 2, 2023
@BlyZeYT
Copy link
Author

BlyZeYT commented Mar 2, 2023

Could you elaborate a bit more about "set any color with an AppThemeBinding."?

How are you doing that exactly? On what element?

I guess in this case we might not need a full-blown GitHub repo to show it, but at least please give some relevant concrete code that we can try to reproduce this issue.

I will send the Code soon I'm not Home yet :)

@jsuarezruiz jsuarezruiz added s/needs-repro Attach a solution or code which reproduces the issue and removed s/needs-attention Issue has more information and needs another look labels Mar 2, 2023
@ghost
Copy link

ghost commented Mar 2, 2023

Hi @BlyZeYT. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@BlyZeYT
Copy link
Author

BlyZeYT commented Mar 2, 2023

Could you elaborate a bit more about "set any color with an AppThemeBinding."?

How are you doing that exactly? On what element?

I guess in this case we might not need a full-blown GitHub repo to show it, but at least please give some relevant concrete code that we can try to reproduce this issue.

MainPage.xaml code:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="LoginManager.MainPage"
             BackgroundColor="{AppThemeBinding Light={StaticResource LightBackground}, Dark={StaticResource DarkBackground}}">

    <ScrollView>
        <VerticalStackLayout
            Spacing="10"
            Padding="25,0"
            VerticalOptions="Center">

            <Border StrokeThickness="5"
                    StrokeShape="RoundRectangle 50,5,5,50"
                    Padding="25"
                    Margin="0,0,0,10"
                    Stroke="{AppThemeBinding Light={StaticResource LightSecondary}, Dark={StaticResource DarkSecondary}}"
                    BackgroundColor="{AppThemeBinding Light={StaticResource LightAccent}, Dark={StaticResource DarkAccent}}"
                    Style="{StaticResource Border}">
                <Label Text="Login Manager"
                       HorizontalTextAlignment="Center"
                       VerticalTextAlignment="Center"
                       FontSize="50"
                       FontAttributes="Bold"
                       Style="{StaticResource Label}"/>
            </Border>

            <Button Text="Leon"
                    FontSize="50"
                    Padding="10,25,10,25"
                    Margin="25,0,25,0"
                    Style="{StaticResource Button}"/>

            <Button Text="Alexandra"
                    FontSize="50"
                    Padding="10,25,10,25"
                    Margin="25,0,25,0"
                    Style="{StaticResource Button}"/>

            <Button Text="Wolfgang"
                    FontSize="50"
                    Padding="10,25,10,25"
                    Margin="25,0,25,0"
                    Style="{StaticResource Button}"/>

        </VerticalStackLayout>
    </ScrollView>

</ContentPage>

App.xaml code:

<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:LoginManager"
             x:Class="LoginManager.App">
    <Application.Resources>
        <Color x:Key="DarkPrimary">#009688</Color>
        <Color x:Key="LightPrimary">#0277BD</Color>
        <Color x:Key="DarkSecondary">#26A69A</Color>
        <Color x:Key="LightSecondary">#03A9F4</Color>
        <Color x:Key="DarkBackground">#212121</Color>
        <Color x:Key="LightBackground">#F5F5F5</Color>
        <Color x:Key="DarkText">#ECEFF1</Color>
        <Color x:Key="LightText">#F1F1F1</Color>
        <Color x:Key="DarkAccent">#FFC107</Color>
        <Color x:Key="LightAccent">#FF5722</Color>

        <Style TargetType="Button" x:Key="Button">
            <Setter Property="BackgroundColor" Value="{AppThemeBinding Light={StaticResource LightPrimary}, Dark={StaticResource DarkPrimary}}"/>
            <Setter Property="CornerRadius" Value="20"/>
            <Setter Property="BorderWidth" Value="5"/>
            <Setter Property="BorderColor" Value="{AppThemeBinding Light={StaticResource LightAccent}, Dark={StaticResource DarkAccent}}"/>
            <Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource LightText}, Dark={StaticResource DarkText}}"/>
        </Style>

        <Style TargetType="Label" x:Key="Label">
            <Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource LightText}, Dark={StaticResource DarkText}}"/>
        </Style>

        <Style TargetType="Border" x:Key="Border">
            <Setter Property="Stroke" Value="{AppThemeBinding Light={StaticResource LightAccent}, Dark={StaticResource DarkAccent}}"/>
            <Setter Property="BackgroundColor" Value="{AppThemeBinding Light={StaticResource LightPrimary}, Dark={StaticResource DarkPrimary}}"/>
        </Style>
    </Application.Resources>
</Application>

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue labels Mar 2, 2023
@BlyZeYT
Copy link
Author

BlyZeYT commented Mar 4, 2023

I tried this too but this doesn't work either, the event isn't even fired.

public App()
{
	InitializeComponent();

        Current.RequestedThemeChanged += SystemThemeChanged;

	MainPage = new AppShell();
}

private void SystemThemeChanged(object sender, AppThemeChangedEventArgs e)
	=> Current.UserAppTheme = e.RequestedTheme == AppTheme.Unspecified ? AppTheme.Light : e.RequestedTheme;

@mattleibow
Copy link
Member

Duplicate of #8236

@mattleibow mattleibow marked this as a duplicate of #8236 Mar 7, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Apr 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-theme Themes, theming i/regression This issue described a confirmed regression on a currently supported version platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants