Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a border to your Xamarin Form Label?

Hello fellow Xamarin Forms users,

I already found out that borders on a label are not supported out of the box by Xamarin Froms. So after some searching is still have no clue how to make it possible. Is it possible to add a border using the custom renderer? If so does someone have an example? and if not does someone have any other out of the box idea to make this possible.

Thank you in advance

like image 824
Diceble Avatar asked Feb 10 '17 12:02

Diceble


2 Answers

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)

like image 104
kb0 Avatar answered Nov 20 '22 00:11

kb0


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

like image 13
Diceble Avatar answered Nov 20 '22 00:11

Diceble