如何解决Xamarin中的单选按钮

时间:2019-07-11 04:43:11

标签: xamarin xamarin.forms

我的Xamarin.Forms应用程序中有一个单选按钮。但是我的App Radio按钮崩溃了并且重叠了。所以在这里我想在我的应用程序中获得2个单选按钮,但是在我的代码中却不是这样。我想要网格中的每个元素,如下所示: Sample Preview

    <Grid>
        <ScrollView Orientation="Vertical">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="160" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid Grid.Row="0" Padding="20">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="400" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="25" />
                        <RowDefinition Height="25" />
                        <RowDefinition Height="50" />
                        <RowDefinition Height="50" />
                    </Grid.RowDefinitions>
                    <Label Grid.Row="0" Grid.Column="0" Text="Care of User - Address" FontAttributes="Bold" TextColor="Black" />
                    <Label Grid.Row="1" Grid.Column="0" Text="Enter the details of the person that the connection will be in care of." FontSize="Small" TextColor="#757575" />
                    <Label Grid.Row="2" Grid.Column="0" Text="Address Status" FontAttributes="Bold" TextColor="Black" />
                    <input:RadioButtonGroupView Grid.Row="2" Grid.Column="1" Orientation="Horizontal" Margin="20,0,0,30" x:Name="localForeignCustomerType">
                        <input:RadioButton Text="Local customer" TextFontSize="14" x:Name="localCustomerRadioButton" />
                        <input:RadioButton Text="Foreign customer" TextFontSize="14" x:Name="foreignCustomerRadioButton" />
                    </input:RadioButtonGroupView>
                </Grid>

            </Grid>

1 个答案:

答案 0 :(得分:0)

在滚动视图中尝试一下

<Grid.RowDefinitions>
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" Padding="10">
    <Grid.RowDefinitions >
        <RowDefinition Height="35" />
        <RowDefinition Height="35" />
        <RowDefinition Height="35" />
    </Grid.RowDefinitions>
    <Label Grid.Row="0" Text="Care of User - Address" FontAttributes="Bold" TextColor="Black" />
    <Label Grid.Row="1" Text="Enter the details of the person that the connection will be in care of." FontSize="Small" TextColor="#757575" />

    <StackLayout Grid.Row="2"   Orientation="Horizontal"  x:Name="localForeignCustomerType" HorizontalOptions="FillAndExpand">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

        </Grid>
        <Label Grid.Row="0" Grid.Column="0" Text="Address Status" FontAttributes="Bold" TextColor="Black" HorizontalOptions="StartAndExpand" />
        <input:RadioButtonGroupView Orientation="Horizontal" Grid.Column="1" Grid.Row="0" HorizontalOptions="EndAndExpand">
            <input:RadioButton Text="Local" TextFontSize="14" x:Name="localCustomerRadioButton"  />
            <input:RadioButton Text="Foreign" TextFontSize="14" x:Name="foreignCustomerRadioButton"  />
        </input:RadioButtonGroupView>

    </StackLayout>
</Grid>