Bug 43711 - BoxView Color being used instead of BackgroundColor
Summary: BoxView Color being used instead of BackgroundColor
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-08-24 17:57 UTC by John Hardman
Modified: 2017-03-28 16:23 UTC (History)
4 users (show)

Tags: BoxView Margin BackgroundColor Color
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description John Hardman 2016-08-24 17:57:57 UTC
As the BoxView view has both a Color and a BackgroundColor property, and has Margin but not padding, I am assuming that if Margin is specified, then the Margin should appear in the BackgroundColor . It does not. The code below shows the Margin appearing in the same Color as the BoxView itself, resulting in a big block of Lime, instead of some Lime and some Pink. It would seem that it is still necessary to wrap a BoxView in a ContentView to have spacing around it, which is what Margin is intended to do.

        const double spaceBelow = 2.0;
        const double separatorHeight = 1.0;

        public static View CreateSeparator(bool showSpaceAbove)
        {
            double spaceAbove = showSpaceAbove ? 50 : 20;

            BoxView separator = new BoxView
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                HeightRequest = spaceAbove + spaceBelow + separatorHeight,
                Margin = new Thickness(0, spaceAbove, 0, spaceBelow),
                BackgroundColor = Color.Pink,
                Color = Color.Lime,
                VerticalOptions = LayoutOptions.Start
            };

            return separator;
        }
Comment 1 adrianknight89 2016-10-16 06:36:10 UTC
Color actually overrides BackgroundColor (not in Core but in Android) if it's not set to Default. Whenever there is a property change on either of these, Color will take precedence. I'm not sure why it was introduced to be honest. I'd be more comfortable just using BackgroundColor.

I think Margin works fine. You could set Margin to have spacing around BoxView, and assume BackgroundColor is pretty much useless.
Comment 2 Paul DiPietro [MSFT] 2017-03-28 16:23:08 UTC
Considering that the docs page (https://developer.xamarin.com/api/type/Xamarin.Forms.BoxView/) describes BoxView as "A View used to draw a solid colored rectangle" it might make sense that it's functioning this way. I do think that the documentation could potentially be a bit more clear about the behavior.