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 BackgroundColor to null does not actually changes BackgroundColor #22914

Open
Jon2G opened this issue Jun 7, 2024 · 6 comments · May be fixed by #22917
Open

Setting BackgroundColor to null does not actually changes BackgroundColor #22914

Jon2G opened this issue Jun 7, 2024 · 6 comments · May be fixed by #22917
Labels
area-controls-general General issues that span multiple controls, or common base classes such as View or Element area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing platform/android 🤖 platform/iOS 🍎 t/bug Something isn't working
Milestone

Comments

@Jon2G
Copy link
Contributor

Jon2G commented Jun 7, 2024

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

@Jon2G Jon2G added the t/bug Something isn't working label Jun 7, 2024
Copy link
Contributor

github-actions bot commented Jun 7, 2024

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
Copy link
Member

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

@aheubusch
Copy link
Contributor

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

Jon2G added a commit to Jon2G/MAUI-BackgroundColorNull that referenced this issue Oct 1, 2024
Using ClearValue as suggested by @PureWeen at dotnet/maui#22914 (comment) seems to work fine
@Jon2G
Copy link
Contributor Author

Jon2G commented Oct 1, 2024

@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
Copy link
Contributor Author

Jon2G commented Oct 1, 2024

@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

<Style TargetType="Label"> <!-- If you define a Style for the View without setting a "default" backgroundColor it will fail to clear the value --> <!--<Setter Property="BackgroundColor" Value="Transparent" />--> <Setter Property="LineBreakMode" Value="WordWrap" /> </Style>

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

Jon2G added a commit to Jon2G/Maui.FreakyEffects that referenced this issue Oct 1, 2024
As @PureWeen suggested calling "ClearValue" instead of setting property to null seems to work.
dotnet/maui#22914 (comment)
@spadapet spadapet removed their assignment Oct 4, 2024
@FreakyAli
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-general General issues that span multiple controls, or common base classes such as View or Element area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing platform/android 🤖 platform/iOS 🍎 t/bug Something isn't working
Projects
None yet
7 participants