Xamarin.Forms - 标签不居中

标签 xamarin xamarin.forms stackview

我有一个包含 2 个标签的 StackView。一个是普通文本,另一个是 FontAwesome Icon。

enter image description here

无论如何,两个标签都没有在 StackView 内垂直居中。这是他们的代码:

样式:

        <Style x:Key="FAIconedLabel" TargetType="Label">
            <Setter Property="TextColor" Value="White"/>
            <Setter Property="FontSize" Value="40" />
            <Setter Property="Margin" Value="0" />
        </Style>

        <Style x:Key="EmailLabel" TargetType="Label">
            <Setter Property="TextColor" Value="White"/>
            <Setter Property="FontSize" Value="20" />
        </Style>

和 View 本身
        <!-- Top Right -->
        <Grid BackgroundColor="{StaticResource LamaControlGray}"
              RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,
                Property=Width,Factor=1,Constant=-400}"
              RelativeLayout.WidthConstraint="{ConstraintExpression
                Type=RelativeToParent,Property=Width,Factor=0,Constant=400}"
              RelativeLayout.HeightConstraint="{ConstraintExpression
                Type=RelativeToParent,Property=Height,Factor=0,Constant=40}" >
            <StackLayout Orientation="Horizontal" HorizontalOptions="End" VerticalOptions="FillAndExpand" BackgroundColor="Red">
                <Label x:Name="LblUserEmail" Margin="0,0,10,0" Text="{Binding UserEmail}" VerticalOptions="FillAndExpand" Style="{StaticResource EmailLabel}"/>
                <fal:FontAwesomeLabel Text="{Binding SettingsIcon}" BackgroundColor="Green" VerticalOptions="CenterAndExpand" Style="{StaticResource FAIconedLabel}" />
            </StackLayout>
        </Grid>

我在这里想念什么吗?

编辑 1

我添加了一个 BackgroundColor 来查看,如果 Label 真的填满了 StackView

enter image description here

编辑 2

清理并重建解决方案后,电子邮件标签现在居中。但图标仍然留在底部

enter image description here

最佳答案

是的,你错过了一些东西。
您没有将其设置为垂直居中。

任何一个

<Label x:Name="LblUserEmail" Margin="0,0,10,0" Text="{Binding UserEmail}" VerticalOptions="FillAndExpand" VerticalTextAlignment="Center" Style="{StaticResource EmailLabel}"/>

或者
<Label x:Name="LblUserEmail" Margin="0,0,10,0" Text="{Binding UserEmail}" VerticalOptions="CenterAndExpand" Style="{StaticResource EmailLabel}"/>

关于Xamarin.Forms - 标签不居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49323660/

相关文章:

ios - 使用 LFLiveKit 在 iOS 应用程序中切换到后置摄像头

Android Autofill 仅处理来自 onFillRequest 的响应,而不处理来自 Authentication Activity 的响应

android - 如何在 Xamarin.Forms 中设置 ContentPage 方向

xamarin - 更改 Xamarin Forms NavigationPage 工具栏的高度

xaml - 如何在 XAML 文本字符串中显示一个符号?

swift - 更新 UIStackView 内部 View 的高度约束

java - 在堆栈 View 中水平滑动

xamarin - Exrin动画

c# - 您将如何在 Xamarin C# for iOS 中创建可堆叠的矩形?

ios - 如何在堆栈 View 中隐藏元素