Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
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
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.
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.