question

imaddiraa-4704 avatar image
0 Votes"
imaddiraa-4704 asked JarvanZhang-MSFT answered

Xamarin Forms, Label with proprety LineBreakMode="MiddleTruncation" can't be shown in 4 line

Hello Everyone,
I'm trying to use the middletruncation attribute in more than one line, but xamarin dosen't allowa me to do that.

is there anyway to do that?


this is my code:

 <?xml version="1.0" encoding="utf-8" ?>
 <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
              x:Class="App9.MainPage">
     <StackLayout>
         <Label FontSize="26" Padding="30,24,30,0" LineBreakMode="MiddleTruncation" MaxLines="4">
             <Label.FormattedText>
                 <FormattedString>
                     <FormattedString.Spans>
                         <Span Text="first span "/>
                         <Span FontSize="26" FontAttributes="Bold" Text="a big line a big line a big line a big line a big line a big line a big line a big line a big line a big line a big line a big line a big 
                               line a big line a big line a big line a big line a big line a big line a big line a big line a big line a big line a big line a big line a big line
                               a big line a big line a big line a big line a big line a big line a big line a big line a big line a big line a big line a big line a big line a big line 
                               a big line a big line a big line a big line a big line a big line a big line a big line a big line a big line a big line a big line "/>
                         <Span Text="third span"/>
                     </FormattedString.Spans>
                 </FormattedString>
             </Label.FormattedText>
         </Label>
     </StackLayout>
 </ContentPage>


this is the result:

130779-middletruncation-result.png




thanks to everyone

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JarvanZhang-MSFT avatar image
0 Votes"
JarvanZhang-MSFT answered

Hello,​

Welcome to our Microsoft Q&A platform!

I'm trying to use the middletruncation attribute in more than one line, but xamarin dosen't allowa me to do that.

We cannot do that. LineBreakMode.MiddleTruncation truncates the middle of text and replaces it with an ellipsis, this function requires to make sure the 'label' is single line. From the result, we can see that set a value to the MaxLine doesn't work.

Xamarin.Forms is an open-source UI framework. Xamarin.Forms allows developers to build Xamarin.Android, Xamarin.iOS, and Windows applications from a single shared codebase. Xamarin.Android or Xamarin.iOS is only a layer of wrapper for Android/iOS native libraries, no extra operations. In native Android, we use setEllipsize command to set the line break mode and the middle mode is bases on setting setSingleLine to true. Here is the related doc, you could refer to: https://developer.android.com/reference/android/widget/TextView#setEllipsize(android.text.TextUtils.TruncateAt)

In native iOS, NSLineBreakMode.byTruncatingMiddle also uses this mode for single-line layout. Here is the documentation: https://developer.apple.com/documentation/uikit/nslinebreakmode/bytruncatingmiddle

Best Regards,

Jarvan Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.