question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BoxView is rendered always with a black background

See original GitHub issue

Description

Background and BackgroundColor properties of BoxView do not work. They are ignored completely and the BoxView has always a black background instead. This has already been reported a few months ago, but the issue has been closed for inactivity (despite the fact that it got some reactions): https://github.com/dotnet/maui/issues/9292

I am reporting the same issue and I have created a repro project to make the reproduction of the bug as simple as possible: https://github.com/holecekp/MauiBoxViewBug

The repro project contains a VerticalStackLayout with a BoxView, Frame, and Rectangle.

<VerticalStackLayout Spacing="0">

   <BoxView HeightRequest="10" Background="Red" />
   <Frame HeightRequest="10" Background="Green" CornerRadius="0" />
   <Rectangle HeightRequest="10" Background="Blue" />

</VerticalStackLayout>

The result should be a red, green, and blue rectangle with the same height. You can see in the screenshots that the result is very far from what is expected. The BoxView is not red but black instead. You can see two other bugs in this very simple example: the height of the controls is incorrect (the Frame is too big on Android, and the Rectangle is too small on Windows), and the zero spacing set for the VerticalStackLayout is ignored for Windows.

Screenshot for Windows - notice the black box instead of the red one (and other bugs) MauiBoxViewBugWin

Screenshot for Android - notice the black box instead of the red one MauiBoxViewBugAndroid

Steps to Reproduce

  1. Clone the repro project: https://github.com/holecekp/MauiBoxViewBug
  2. Run it on Windows. You can see that BoxView color is broken and that it is rendered in black instead of the red color. By the way, you can see also other bugs on the same page.
  3. You can run it on Android to check that it is also broken.

Link to public reproduction project repository

https://github.com/holecekp/MauiBoxViewBug

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows, I was not able test on other platforms

Affected platform versions

Windows 10, Android 12 but it probably does not work anywhere

Did you find any workaround?

No. In very simple cases (like the one in the repro project), you can try Frame, or Rectangle as a replacement for BoxView, but, it might be impossible to find a workaround in more complex real-life scenarios. I have not been able to find a sufficient replacement for BoxView for my app because Frame and Rectangle have they their own positioning bugs when more complex layouts are used. When you need to use a LinearGradientBrush instead of a solid color, you can expect another differences in the three controls so I found it impossible to workaround the issue in a more complex realistic scenario.

Relevant log output

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
BioTurboNickcommented, Nov 12, 2022

Workaround, thanks to reading the thread @HausBJB posted: Color works for me. BackgroundColor does not.

0reactions
BioTurboNickcommented, Nov 12, 2022

My guess is that the default Styles.xaml dictionary, which sets Color on all BoxView objects, is silencing the BackgroundColor property. That other issue says that if Color is set, it will be used instead of BackgroundColor.

<Style TargetType="BoxView">
    <Setter Property="Color" Value="{AppThemeBinding Light={StaticResource Gray950}, Dark={StaticResource Gray200}}" />
</Style>

EDIT: Confimed, if you delete this Styles.xaml entry or change it to BackgroundColor, BackgroundColor works again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MAUI BoxView unable to set Background Color - xaml
Net MAUI I created a BoxView and am unable to change the Background Color... it remains Black regardless of what color I set....
Read more >
Xamarin.Forms BoxView
BoxView renders a simple rectangle of a specified width, height, and color. You can use BoxView for decoration, rudimentary graphics, ...
Read more >
Working with Gradients - Grial Docs
The default value for the Angle is 0 , so the gradient is rendered vertically, from bottom to top. Let's see the Angle...
Read more >
Only See Camera View in Viewport and Black Out ...
So I saw people have the camera only show the rendered image in the viewport with the entire background blacked out. How do...
Read more >
Xamarin.Forms Layout
Here, we will make the box and set it on our background page. Here are the few things that should be kept in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found