如何在Label中设置marging到长文本,分为两行

时间:2018-01-30 11:27:24

标签: xaml xamarin.forms

我的AbsoluteLayout中有一个Label,当Label的文本很长时,将文本放入两行,这是可以的,但是也可以获得第二个左边包裹线的边距吗?我附上图片以更好地展示我的意思,在那张图片中有红色箭头显示我所要求的地方。

感谢所有人!

Image

<Grid HorizontalOptions="Center"
      VerticalOptions="Center">
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <AbsoluteLayout HorizontalOptions="Start">
        <Image HeightRequest="160" 
               HorizontalOptions="Start" 
               WidthRequest="360" 
               Aspect="AspectFill" 
               Grid.Row="0"  
               Source="{Binding EnclosureUrl}" 
               Margin="0,0,0,15">                            
            <Image.GestureRecognizers>
                <TapGestureRecognizer Tapped="TappedItemCommand"
                                      CommandParameter="{Binding Link}"
                                      NumberOfTapsRequired="1" />
            </Image.GestureRecognizers>                            
        </Image>
        <Label Grid.Row="0" Grid.Column="0"
               HorizontalOptions="Start"
               Margin="0,0,0,40"
               WidthRequest="250"
               Style="{StaticResource BoldBasicText}"
               Font="Bold,20"
               AbsoluteLayout.LayoutFlags="PositionProportional"
               AbsoluteLayout.LayoutBounds="0,1,-1,-1"
               BackgroundColor="{x:Static ownStyles:StyleSettings.colCaptionColorFade}"
               TextColor="{x:Static StyleSettings:Settings.colRed}"
               Text="{Binding Header}">
            <Label.GestureRecognizers>
                <TapGestureRecognizer Tapped="TappedItemCommand"
                                      CommandParameter="{Binding Link}"
                                      NumberOfTapsRequired="1" />                                               
            </Label.GestureRecognizers>
        </Label>
    </AbsoluteLayout>
</Grid>

1 个答案:

答案 0 :(得分:1)

您可以使用Xamarin.Forms中提供的换行模式: -

LineBreakMode = “自动换行”

<Label Text="{Binding Certification, StringFormat='Board Certification:{0:F0}'}" LineBreakMode="WordWrap"/>

请参阅下面的链接: -

Xamarin Text Line Break Mode

Label wrapping with StackLayout