Separators in Xamarin.Forms

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!


@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


You can define your own separator line in the app.xaml file.

<Style x:Key="Separator" TargetType="BoxView">
            <Setter Property="HeightRequest" Value="1" />
            <Setter Property="HorizontalOptions" Value="FillAndExpand" />
            <Setter Property="Color" Value="Gray" />
            <Setter Property="Margin" Value="0, 5, 0, 5" />
            <Setter Property="Opacity" Value="0.5" />
</Style>

And use it as Style.

<BoxView Style="{StaticResource Separator}" />

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.