使用StackLayout标记包装

问题描述 投票:13回答:2

我正在使用Xamarin并使用XAML创建我的视图,我无法为我的生活获得这个标签以我想要的方式包装。如果标签到达屏幕的边缘,我希望它像这样包裹......

This is the way I want it to look

现在它看起来像这样......

This is how it is showing up

这是我的代码:

<StackLayout Orientation="Vertical" HorizontalOptions="StartAndExpand" BindingContext="{Binding CurrentProviderDetails}" Padding="20,20,20,20" >
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>
<!--Certification Board-->
  <StackLayout Orientation="Horizontal" HorizontalOptions="StartAndExpand" Grid.Row="0" Grid.Column="0" >
    <Label Text="Certification Board: " FontSize="13" HorizontalOptions="Fill" VerticalOptions="CenterAndExpand" />
    <Label Text="{Binding Certification}" VerticalOptions="CenterAndExpand"  HorizontalOptions="Center" Font="17" LineBreakMode="WordWrap"/>
  </StackLayout>
 </Grid>
</StackLayout>

这不需要在网格中;这只是我现在尝试的方法。我唯一的要求是'认证委员会'是一个标签,我必须传入一个字,当它到达屏幕的末尾时,它会换行。任何帮助都会很棒,谢谢!

xaml xamarin label textwrapping
2个回答
13
投票

在标签中放置一个LineBreakMode =“NoWrap”标签。这样你就可以避免换行。

但如果你没有足够的空间,这个词就会被删除。


2
投票

通过将水平对齐的StackLayout中包含的两个标签组合到一个Label中并设置LineBreakMode =“WordWrap”,可以实现所需的外观。 XAML有一个很棒的功能,叫做StringFormat。您可以使用它将静态“认证委员会:”文本添加到绑定的认证属性。您的标签应如下所示:

<Label Text="{Binding Certification, StringFormat='Board Certification:{0:F0}'}" LineBreakMode="WordWrap"/>
© www.soinside.com 2019 - 2024. All rights reserved.