Label wrapping with StackLayout

后端 未结 3 1689
情话喂你
情话喂你 2021-01-07 17:46

I\'m using Xamarin and creating my view with XAML and I cannot for the life of me get this label to wrap the way I want it to. If the label gets to the edge of the screen, I

相关标签:
3条回答
  • 2021-01-07 18:39

    You can achieve the desired look by combining both of the Labels contained in your horizontally aligned StackLayout into a single Label and setting LineBreakMode="WordWrap". XAML has a great feature known as StringFormat. You can use this to prepend the static "Certification Board:" text to the bound Certification property. Your Label should look like this:

    <Label Text="{Binding Certification, StringFormat='Board Certification:{0:F0}'}" LineBreakMode="WordWrap"/>
    
    0 讨论(0)
  • 2021-01-07 18:42

    Add two columns to your grid and remove stacklayout around the labels, as shown below

    <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" />
                     <ColumnDefinition Width="*" />
                 </Grid.ColumnDefinitions>
                 <!--Certification Board-->
                 <Label Grid.Row="0" Grid.Column="0" Text="Certification Board: " FontSize="13" HorizontalOptions="FillAndExpand" />
                 <Label Grid.Row="0" Grid.Column="1" Text="{Binding Certification}" HorizontalOptions="FillAndExpand" Font="17"/>
         </Grid>
    </StackLayout>
    

    You can more rows like this by adding like below

    <Label Grid.Row="1" Grid.Column="0" Text="Certification Name: " FontSize="13" HorizontalOptions="FillAndExpand" />
    <Label Grid.Row="1" Grid.Column="1" Text="{Binding CertificationName}" HorizontalOptions="FillAndExpand" Font="17"/>
    
    0 讨论(0)
  • 2021-01-07 18:48

    Put a LineBreakMode="NoWrap" tag in your labels. This way you can avoid the wrap.

    But if you don't have enough space, the word will be cut.

    0 讨论(0)
提交回复
热议问题