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.98k stars 1.72k forks source link

OnPlatform doesn't work with AppThemeBinding on Windows in Release mode. #19388

Closed gairmuse closed 2 days ago

gairmuse commented 9 months ago

Description

Conditionally set the BackgroundColor of the MainPage of a new project using OnPlatform and AppThemeBinding and it will not work in Release mode. Works fine in Debug mode. BackgroundColor="{OnPlatform WinUI={AppThemeBinding Dark=Yellow, Light=Blue, Default=White}, Default=Green}"

The page renders with a black background (in Dark mode).

Steps to Reproduce

Create new .NET 8.0 MAUI App project in Visual Studio then add the following line to MainPage.xaml inside ContentPage. BackgroundColor="{OnPlatform WinUI={AppThemeBinding Dark=Yellow, Light=Blue, Default=White}, Default=Green}"

Link to public reproduction project repository

https://github.com/gairmuse/MauiOnPlatformBug

Version with bug

8.0.3

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

7.0.101

Affected platforms

Windows

Affected platform versions

Windows 10.0.19041.0

Did you find any workaround?

Not really. BackgroundColor can be set in code.

Relevant log output

No response

ghost commented 8 months ago

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.

vhugogarcia commented 4 months ago

This issue also occurs on iOS and Android. cc: @jsuarezruiz do you know if this issue is already fixed by a PR? Thanks in advance.

MartyIX commented 1 month ago

@vhugogarcia Cheers. Is it possible that the bug is fixed? I ran a sample MAUI app on Mac Catalyst using

dotnet build -t:run -c Release  --framework net8.0-maccatalyst

and it produced:

https://github.com/user-attachments/assets/a6e520e5-2047-436e-92cf-cf283106c836

XAML was as follows:

<Label
    Text="Hello, World!"
    Style="{StaticResource Headline}"
    SemanticProperties.HeadingLevel="Level1" 
    BackgroundColor="{OnPlatform MacCatalyst={AppThemeBinding Light=Blue, Dark=Yellow, Default=White}, Default=Green}"/>

and it looks OK to me.

I can test on Windows later on.

vhugogarcia commented 1 month ago

Thanks @MartyIX , it is probably fixed, yes 😃 . Could you give us a hand to test it on iOS, Android and Windows as well? please 🙏🏻

MartyIX commented 1 month ago

I can easily test on Windows.

Not so much experience with iOS and Android but I guess I can learn some new stuff.

vhugogarcia commented 1 month ago

I can easily test on Windows.

Not so much experience with iOS and Android but I guess I can learn some new stuff.

Sounds good, let us know the results. Thank you!

gairmuse commented 1 month ago

@MartyIX The issue was reported on Windows. Not sure there is any value testing on Mac.

MartyIX commented 1 month ago

@MartyIX The issue was reported on Windows. Not sure there is any value testing on Mac.

I did that simply because of this comment which sort of suggested that the problem is on all platforms: https://github.com/dotnet/maui/issues/19388#issuecomment-2061489154

Anyway, on Windows in the release configuration it behaves like this with the latest released version:

animation

So it's not fixed.