You can set a LineBreakMode attribute to a Label that can have the following values:
If you have a text that is to large to fit the width of your label, you can use the attribute called LineBreakMode=TailTruncation.
This will display a text with “…” at the end (ellipsis) when the text doesn’t fit. Let’s take for example this text: “Welcome to Xamarin Forms” inside a Label like in the exmple below:
<?xml version="1.0" encoding="utf-8"?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:Test" x:Class="Test.MainPage"> <StackLayout Orientation="Horizontal" HorizontalOptions="Fill" VerticalOptions="Center"> <!-- Place new controls here --> <Button Text="Press Me" WidthRequest="150" HeightRequest="100" /> <Label Text="Welcome to Xamarin Forms!" FontSize="Large" LineBreakMode="TailTruncation"/> <Button Text="Press Me" WidthRequest="100" HeightRequest="100" /> </StackLayout> </ContentPage>
The text is to long to fit the label width so it will display as much as it fits from the text with ellipsis at the end like in the image bellow:
HeadTruncation will display the ellipsis (…) at the beginning:
MiddleTruncation will display the ellipsis (…) in the middle:
CharacterWrap will wrap the word by character.
WordWrap will wrap by words.
NoWrap will let text to be displayed as much as it can.
Search In Blog
Want to donate?
Recent Posts: My Android Solutions
If you ever wondered how to read and parse a simple JSON file stored in the assets directory of your Android project, here is a way to do it.
In this tutorial I will create a simple Sectioned RecyclerView that will show 2 sections and a few items in each section and how to move an item from one section to another. Note: For RecyclerView I used AndroidX imports and not android.support.v7.widget.RecyclerView! Setup We need to import the recycler view from AndroidX. The build.gradle…
Recently, I had to add a perfect square CardView and I wanted to achieve this without hardcoding its width and height. I happily discovered the power of ConstraintLayout and this is how I managed to create a perfect square which should work on every dimension. In my project I created a RecyclerView with 2 columns,…