How to add a border to your Xamarin Form Label?

Despite there already being an answer, the solution I found allows you to choose which borders you specifically want to show and how much.

A fix that I used was to wrap the element that needs a border in a ContentView, give that ContentView a backgroundColour and a padding. The code is below

Resourcedictionary with the following style declared

<Style TargetType="ContentView"
       x:Key="BorderContentView">
    <Setter Property="BackgroundColor"
            Value="Black" />
    <Setter Property="Padding"
            Value="1 2 1 3" />
    <!-- Tweak the values above to set your borders however you prefer -->
</Style>

In your view, simply add a wrapping ContentView and add the style to it

<ContentView Style="{DynamicResource BorderContentView}">
    <!-- Elements with a border here --> 
</ContentView>

I was thinking a little out of the box and came up with using a boxview to use as a border. Here you have a sample of the code that I wrote:

  <StackLayout x:Name="BasicInfo" Margin="10,10,10,5" Grid.Row="0" Grid.Column="0">
    <Label Text="Basic Info" FontSize="20"/>
    <BoxView Color="Black" WidthRequest ="100" HeightRequest="1"/>
     <Label x:Name="text1" />
     <Label x:Name="text2"/>
     <Label x:Name="text3"/>
     <Label x:Name="text4"/>  
  </StackLayout>

I'll also add a picture of the result it gives me: enter image description here


You can add a Label within Frame element, and setup OutlineColor for Frame:

<Frame OutlineColor="Black">
    <Label Text="My Label With Frame" />
</Frame>

If you want to use custom renderer, you should implement custom renderer for each platform you want to support (i.e. Android, iOS, UWP, WinPhone)