Xamarin -如何创建居中文本的水平线(XAML)

tyky79it  于 2023-03-16  发布在  其他
关注(0)|答案(1)|浏览(146)

我已经尝试了很多天,但没有成功。我正在尝试做同样的事情,而不是这个图像:

因此,我的意图是在XAML中创建一个简单的栏,将居中的文本添加到注册页面和注册页面,但我真的不知道如何在Xamarin Essentials 1.7.5和.NET Standard 2.1上使用XAML来完成它。这个项目是在Visual Studio 2022上使用C#作为编程语言构建的。尝试创建一个像这样的2行网格,但没有按预期工作。

<Grid ColumnDefinitions="Auto,*">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <BoxView Grid.Row="0" HeightRequest="1" BackgroundColor="White" Margin="10,0,10,0"/>
                    <Label Grid.Row="1" Text="OR" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
                </Grid>

有人能帮我吗?先谢了。

ne5o7dgx

ne5o7dgx1#

创建包含三列的网格:

<Grid ColumnDefinitions="*,auto,*">
      <Grid.Resources>
            <Style TargetType="BoxView">
                  <Setter Property="Color" Value="Gray"/>
                  <Setter Property="HorizontalOptions" Value="FillAndExpand"/>
                  <Setter Property="VerticalOptions" Value="Center"/>
                  <Setter Property="HeightRequest" Value="1"/>
            </Style>
      </Grid.Resources>
      <BoxView Grid.Column="0"/>
      <Label Text="OR" Grid.Column="1"/>
      <BoxView Grid.Column="2"/>
</Grid>

这将创建一个中间带有“或”的行。您可以在BoxView中添加一些边距,以便它满足您的需要。

相关问题