xamarin/Xamarin.Forms

Vertical alignment of Label with FormattedString not centering

オープン

#4,239 opened on 2018/10/27

 (8 件のコメント) (8 件のリアクション) (0 人の担当者)C# (1,926 件のフォーク)batch import
e/4 :clock4:help wantedt/bug :bug:up-for-grabs

Repository metrics

Stars
 (5,644 個のスター)
PR merge metrics
 (30d に merged PR はありません)

説明

Description

Steps to Reproduce

This XAML produces the header as seen in shot 1. The word Brian is centered vertically and horizontally.

    <NavigationPage.TitleView>
        <StackLayout 
            Orientation="Horizontal" 
            VerticalOptions="CenterAndExpand" 
            HorizontalOptions="FillAndExpand">
            <Label 
                HorizontalTextAlignment="Center"
                VerticalOptions="Center" 
                VerticalTextAlignment="Center"
                HorizontalOptions="FillAndExpand"
                Margin="0,0,50,0"
                FontAttributes="Bold" FontSize="22" TextColor="Black" Text="Brian">
            </Label>

            <Button     
                BackgroundColor="Transparent"
                Text="&#xe147;" 
                WidthRequest="50"
                VerticalOptions="Center" 
                HorizontalOptions="End" 
                FontSize="28" 
                Clicked="Button_AddGoal">
                <Button.FontFamily>
                    <OnPlatform x:TypeArguments="x:String">
                        <On Platform="iOS">MaterialIcons-Regular</On>
                        <On Platform="Android">MaterialIcons-Regular.ttf#Material Icons</On>
                        <On Platform="UWP">Assets/MaterialIcons-Regular.ttf#Material Icons</On>
                    </OnPlatform>
                </Button.FontFamily>
            </Button>
        </StackLayout>
    </NavigationPage.TitleView>

However in this version, where I've added some FormattedString formatting, the vertical position is too low. See shot 2. The Acqua background is there to illustrate the size and position of the Label only:

    <NavigationPage.TitleView>
        <StackLayout 
            Orientation="Horizontal" 
            VerticalOptions="CenterAndExpand" 
            HorizontalOptions="FillAndExpand">
            <Label 
                BackgroundColor="Aqua"
                HorizontalTextAlignment="Center"
                VerticalOptions="Center" 
                VerticalTextAlignment="Center"
                HorizontalOptions="FillAndExpand"
                Margin="0,0,50,0">
                <Label.FormattedText>
                    <FormattedString >
                        <Span FontAttributes="Bold" FontSize="22" TextColor="Black" Text="Brian"/>
                        <Span FontAttributes="Bold" FontSize="40" TextColor="#6200EE" Text="."/>
                    </FormattedString>
                </Label.FormattedText>
            </Label>

            <Button     
                BackgroundColor="Transparent"
                Text="&#xe147;" 
                WidthRequest="50"
                VerticalOptions="Center" 
                HorizontalOptions="End" 
                FontSize="28" 
                Clicked="Button_AddGoal">
                <Button.FontFamily>
                    <OnPlatform x:TypeArguments="x:String">
                        <On Platform="iOS">MaterialIcons-Regular</On>
                        <On Platform="Android">MaterialIcons-Regular.ttf#Material Icons</On>
                        <On Platform="UWP">Assets/MaterialIcons-Regular.ttf#Material Icons</On>
                    </OnPlatform>
                </Button.FontFamily>
            </Button>
        </StackLayout>
    </NavigationPage.TitleView>

Expected Behavior

The text should be vertically centered.

Actual Behavior

The label appears to be at the end instead.

Basic Information

  • Version with issue: 3.4.0.925479-pre1

  • Last known good version: N/A

  • IDE: Visual Studio 2017 15.8.8

  • Android: 8.1

コントリビューターガイド