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
22.26k stars 1.76k forks source link

Setting BackgroundColor to null does not actually changes BackgroundColor #22914

Open Jon2G opened 5 months ago

Jon2G commented 5 months ago

Description

Probably root cause of #19576 Android/iOS (Windows works fine) If you set the BackgroundColor to null nothing will happen.

Steps to Reproduce

Simply try to change BackgroundColor of a Page to null by binding or directly

<ContentPage ... BackgroundColor="Gray"> ... </ContentPage>
public partial class MainPage : ContentPage
{
.....
    private void RestoreBackground()
    {
        this.BackgroundColor = null; // Color will remain gray
    }
.....
}

https://github.com/Jon2G/MAUI-BackgroundColorNull/raw/main/Capture.PNG

Link to public reproduction project repository

https://github.com/Jon2G/MAUI-BackgroundColorNull

Version with bug

8.0.40 SR5

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android

Affected platform versions

Android 33,34

Did you find any workaround?

If you set the BackgroundColor to transparent or any other it will work but its not optimal

Relevant log output

No response

github-actions[bot] commented 5 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

PureWeen commented 2 months ago

@Jon2G what if you call "ClearValue" vs setting it to null?

aheubusch commented 1 month ago

If nothing has changed in the last 2 ish years then this is explicitly not supported. #1485 and #5317

Jon2G commented 1 month ago

@PureWeen calling "ClearValue" instead of setting property to null seems to work, i have updated the reproduction project. https://github.com/Jon2G/MAUI-BackgroundColorNull

Jon2G commented 1 month ago

@PureWeen I'm afraid i find a case where "ClearValue" does not works.

If you define a Style for the View without setting a "default" backgroundColor it will fail to clear the value

``

A simple label <Label x:Name="labelTest" BackgroundColor="Gray" Text="This text should be visible" TextColor="Gray" />

Then try to remove gray background with: labelTest.ClearValue(Label.BackgroundColorProperty); //this DON'T work

I have updated the reproduction project. https://github.com/Jon2G/MAUI-BackgroundColorNull

FreakyAli commented 1 month ago

@PureWeen What do you recommend we do in the above mentioned case?