首页 > 解决方案 > xamarin 表单按钮文本换行到 2 行

问题描述

上面的代码工作正常,但对于下面的代码,按钮应该显示在单行中,但它会换行为 2 行。

<Frame CornerRadius="10"  Grid.Row="1"
OutlineColor="#FF00BBEE"  Margin="2,2"
Padding="0">
    <StackLayout Padding="0">
        <Grid Padding="0">
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <Label Grid.Row="0" TextColor="Black" FontSize="Large" Text="   B.Sc(Physician Assistant)" HorizontalOptions="Start"  VerticalOptions="CenterAndExpand" FontAttributes="Bold"></Label>
            <Label Grid.Row="1" TextColor="Black" FontSize="Medium" Text="   Duration:3 Years + 1 Year Internship" HorizontalOptions="Start"  VerticalOptions="CenterAndExpand" FontAttributes="Italic"></Label>
            <Label Grid.Row="2" TextColor="Black" FontSize="Medium" Text="   Eligibility: +2 Pass with Biology as one subject" HorizontalOptions="Start"  VerticalOptions="CenterAndExpand"></Label>
            <Grid Grid.Row="3">
                <Button HorizontalOptions="Center" Text="Apply Now"   VerticalOptions="CenterAndExpand"></Button>
            </Grid>
        </Grid>                  
    </StackLayout>
</Frame>

标签: xamarin.forms

解决方案


什么是上面的代码?根据您的代码,您的意思是Grid中有四个RowDefinitions,Label和Button应该具有相同的高度?

对于 Grid 的 RowDefinitions,RowDefinition.Height 属性的默认值为 *。所以每个 RowDefinition 都有相同的高度,但是你为每个 Label 和 Button 添加了VerticalOptions="CenterAndExpand",所以这个属性会改变高度以适应视图的内容。

如果我删除VerticalOptions="CenterAndExpand",您可以看到每个 RowDefinition 具有相同的高度。

<Frame
            Margin="2.2"
            Padding="0"
            CornerRadius="10"
            OutlineColor="#FF00BBEE">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Label
                    Grid.Row="0"
                    BackgroundColor="Red"
                    FontSize="Large"
                    Text="   B.Sc(Physician Assistant)"
                    TextColor="Black"
                    />
                <Label
                    Grid.Row="1"
                    BackgroundColor="Aquamarine"
                    Text="   Duration:3 Years + 1 Year Internship"
                    TextColor="Black"
                    />
                <Label
                    Grid.Row="2"
                    BackgroundColor="Beige"
                    Text="   Eligibility: +2 Pass with Biology as one subject"
                    TextColor="Black"
                     />

                <Button Grid.Row="3" Text="Apply Now" BackgroundColor="BlueViolet" />

            </Grid>

        </Frame>

在此处输入图像描述


推荐阅读