Separators in Xamarin.Forms

I'd like to use horizontal separator lines in a form. As far as I found out, Xamarin.Forms doesn't provide one.

Could someone provide a snippet for separators?

UPDATE 1

According to Jason's proposal, this looks fine:

// draws a separator line and space of 5 above and below the separator    
new BoxView() { Color = Color.White, HeightRequest = 5  },
new BoxView() { Color = Color.Gray, HeightRequest = 1, Opacity = 0.5  },
new BoxView() { Color = Color.White, HeightRequest = 5  },

Renders the below separator line:

enter image description here


Solution 1:

You might try using BoxView

// sl is a StackLayout
sl.Children.Add(new BoxView() { Color = Color.Black, WidthRequest = 100, HeightRequest = 2 });

although in my test, the width request is not being followed. This may be a bug, or other settings might be interfering with it.

Solution 2:

There is actually a method to display the separators in Xamarin.Forms:

myListView.SeparatorVisibility = Xamarin.Forms.SeparatorVisibility.Default;
myListView.SeparatorColor = Color.FromHex("C8C7CC");

And to hide:

myListView.SeparatorVisibility = Xamarin.Forms.SeparatorVisibility.None;

Hope it helps!

Solution 3:

@Jason In addition to Jason answer you should set VerticalOptions to be able to use HeightRequest, and set HorizontalOptions to be able to use WidthRequest. default values are fill so that is why it does not respond. Example output

<BoxView   VerticalOptions="Center"
           HorizontalOptions="Center"
           HeightRequest="1"
           WidthRequest="50"  
           Color="#5b5d68"></BoxView>

enter image description here