如何解决Xamarin中的网格和框错误

时间:2019-07-11 09:12:10

标签: xamarin xamarin.forms

我的Xamarin.Forms应用程序中有一个GridLayout。但是我的应用程序我使用BoxView。所以在这里我想在那个boxview中重新使用大小。在我的应用程序中,当我单击[exixing user]时,它的工作正常,但是当我单击新的单选按钮时,崩溃了。在我的应用中,但是在我的代码中却不是这样。我想要网格中的每个元素,如下所示:

Click me and help me Existing and help me

        <ContentPage.Content>
            <ScrollView>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="50" />
                    </Grid.RowDefinitions>
                    <Grid Grid.Row="0" Padding="20">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="40" />
                            <RowDefinition Height="20" />
                            <RowDefinition Height="40" />
                            <RowDefinition x:Name="addressBoxViewRow" />
                        </Grid.RowDefinitions>
                        <Label Text="Care of User - Address" Grid.Row="0" FontAttributes="Bold" FontSize="Default" TextColor="Black" />
                        <Label Text="Enter the details of the person that the connection will be in care of." TextColor="#757575" Grid.Row="1" FontSize="Small" />
                        <FlexLayout Grid.Row="2" AlignItems="Center" JustifyContent="Start" Direction="Row">
                            <Label Text="Address status" FontSize="Small" FontAttributes="Bold" VerticalTextAlignment="Center" TextColor="Black" />
                            <input:RadioButtonGroupView Margin="20,0,0,0" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal" x:Name="addressStatus" VerticalOptions="CenterAndExpand">
                                <input:RadioButton Text="New" TextFontSize="14" x:Name="newRadioButton" Clicked="NewRadioButton_Clicked" />
                                <input:RadioButton Text="Existing" IsChecked="true" TextFontSize="14" x:Name="existingRadioButton" Clicked="ExistingRadioButton_Clicked" />
                            </input:RadioButtonGroupView>
                        </FlexLayout>
                        <BoxView Grid.Row="3" BackgroundColor="White" CornerRadius="5">
                            <BoxView.Effects>
                                <effects:ShadowEffect />
                            </BoxView.Effects>
                        </BoxView>
                        <!--This appears when Existing selected-->
                        <Grid Grid.Row="3" Padding="20" x:Name="existingAddressForm">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="40" />
                                <RowDefinition Height="20" />
                                <RowDefinition Height="20" />
                                <RowDefinition Height="25" />
                                <RowDefinition Height="20" />
                                <RowDefinition Height="25" />
                                <RowDefinition Height="20" />
                                <RowDefinition Height="25" />
                                <RowDefinition Height="20" />
                                <RowDefinition Height="25" />
                            </Grid.RowDefinitions>
                            <Label Grid.Row="0" Text="Billing address" FontAttributes="Bold" FontSize="Default" TextColor="Black" />
                            <Label Text="Address line 1" Grid.Row="1" TextColor="#757575" FontSize="Small" />
                            <Label Grid.Row="2" x:Name="lblAddressLine1" FontAttributes="Bold" FontSize="Medium" />
                            <Label Text="Address line 2" Grid.Row="3" TextColor="#757575" FontSize="Small" />
                            <Label Grid.Row="4" x:Name="lblAddressLine2" FontAttributes="Bold" FontSize="Medium" />
                            <Label Text="Address line 3" Grid.Row="5" TextColor="#757575" FontSize="Small" />
                            <Label Grid.Row="6" x:Name="lblAddressLine3" FontAttributes="Bold" FontSize="Medium" />
                            <Label Text="Postal code" Grid.Row="7" TextColor="#757575" FontSize="Small" />
                            <Label Grid.Row="8" x:Name="lblPostalCode" FontAttributes="Bold" FontSize="Medium" />
                        </Grid>
                        <!--This appears when New selected-->
                        <Grid Grid.Row="3" Padding="20" x:Name="newAddressForm">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="40" />
                                <RowDefinition Height="20" />
                                <RowDefinition Height="20" />
                                <RowDefinition Height="25" />
                                <RowDefinition Height="20" />
                                <RowDefinition Height="25" />
                                <RowDefinition Height="20" />
                                <RowDefinition Height="25" />
                                <RowDefinition Height="20" />
                            </Grid.RowDefinitions>
                            <Label Grid.Row="0" Text="Billing address" FontAttributes="Bold" FontSize="Default" TextColor="Black" />
                            <Label Text="Address line 1" Grid.Row="1" TextColor="#757575" FontSize="Small" />
                            <Entry Grid.Row="2" x:Name="addressLine1" FontAttributes="Bold" FontSize="Medium" />
                            <Label Text="Address line 2" Grid.Row="3" TextColor="#757575" FontSize="Small" />
                            <Entry Grid.Row="4" x:Name="addressLine2" FontAttributes="Bold" FontSize="Medium" />
                            <Label Text="Address line 3" Grid.Row="5" TextColor="#757575" FontSize="Small" />
                            <Entry Grid.Row="6" x:Name="addressLine3" FontAttributes="Bold" FontSize="Medium" />
                            <Label Text="Postal code" Grid.Row="7" TextColor="#757575" FontSize="Small" />
                            <Picker Grid.Row="8" TextColor="Black" FontSize="Small" x:Name="postalCodeSelector1" ItemDisplayBinding="{Binding PostalDescription}" WidthRequest="100">
                                <Picker.Effects>
                                    <effects:DropdownEffect />
                                </Picker.Effects>
                            </Picker>
                        </Grid>
                    </Grid>
                    <StackLayout Grid.Row="1" Orientation="Horizontal" VerticalOptions="End">
                        <Button Text="Clear" Style="{x:StaticResource GrayButton}" HorizontalOptions="FillAndExpand" Clicked="ClearBtn_Clicked"/>
                        <Button Text="Proceed" HorizontalOptions="FillAndExpand" Clicked="Handle_Clicked" x:Name="proceedBtn" />
                    </StackLayout>

                    <!--<StackLayout Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" IsVisible="{Binding IsBusy}" BackgroundColor="White" Opacity="1" Orientation="Vertical">
                        <StackLayout Orientation="Vertical" HorizontalOptions="Center" VerticalOptions="CenterAndExpand">
                            <ActivityIndicator Color="#2B428E" IsRunning="true" />
                            <Label x:Name="progressname" Text="Please wait ..." TextColor="#2B428E" VerticalOptions="Center" />
                        </StackLayout>
                    </StackLayout>-->
                </Grid>
            </ScrollView>
        </ContentPage.Content>

1 个答案:

答案 0 :(得分:0)

尝试一下

   <ScrollView>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid Grid.Row="0" Padding="20">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="40" />
                    <RowDefinition Height="20" />
                    <RowDefinition Height="40" />
                    <RowDefinition x:Name="addressBoxViewRow" />
                </Grid.RowDefinitions>
                <Label Text="Care of User - Address" Grid.Row="0" FontAttributes="Bold" FontSize="Default" TextColor="Black" />
                <Label Text="Enter the details of the person that the connection will be in care of." TextColor="#757575" Grid.Row="1" FontSize="Small" />
                <FlexLayout Grid.Row="2" AlignItems="Center" JustifyContent="Start" Direction="Row">
                    <Label Text="Address status" FontSize="Small" FontAttributes="Bold" VerticalTextAlignment="Center" TextColor="Black" />
                    <input:RadioButtonGroupView Margin="20,0,0,0" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal" x:Name="addressStatus" VerticalOptions="CenterAndExpand">
                        <input:RadioButton Text="New" TextFontSize="14" x:Name="newRadioButton" Clicked="NewRadioButton_Clicked" />
                        <input:RadioButton Text="Existing" IsChecked="true" TextFontSize="14" x:Name="existingRadioButton" Clicked="ExistingRadioButton_Clicked" />
                    </input:RadioButtonGroupView>
                </FlexLayout>
                <BoxView Grid.Row="3" BackgroundColor="White" CornerRadius="5">
                    <BoxView.Effects>
                        <effects:ShadowEffect />
                    </BoxView.Effects>
                </BoxView>
                <!--This appears when Existing selected-->
                <Grid Grid.Row="3" Padding="20" x:Name="existingAddressForm">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="40" />
                        <RowDefinition Height="20" />
                        <RowDefinition Height="20" />
                        <RowDefinition Height="25" />
                        <RowDefinition Height="20" />
                        <RowDefinition Height="25" />
                        <RowDefinition Height="20" />
                        <RowDefinition Height="25" />
                        <RowDefinition Height="20" />
                        <RowDefinition Height="25" />
                    </Grid.RowDefinitions>
                    <Label Grid.Row="0" Text="Billing address" FontAttributes="Bold" FontSize="Default" TextColor="Black" />
                    <Label Text="Address line 1" Grid.Row="1" TextColor="#757575" FontSize="Small" />
                    <Label Grid.Row="2" x:Name="lblAddressLine1" FontAttributes="Bold" FontSize="Medium" />
                    <Label Text="Address line 2" Grid.Row="3" TextColor="#757575" FontSize="Small" />
                    <Label Grid.Row="4" x:Name="lblAddressLine2" FontAttributes="Bold" FontSize="Medium" />
                    <Label Text="Address line 3" Grid.Row="5" TextColor="#757575" FontSize="Small" />
                    <Label Grid.Row="6" x:Name="lblAddressLine3" FontAttributes="Bold" FontSize="Medium" />
                    <Label Text="Postal code" Grid.Row="7" TextColor="#757575" FontSize="Small" />
                    <Label Grid.Row="8" x:Name="lblPostalCode" FontAttributes="Bold" FontSize="Medium" />
                </Grid>
                <!--This appears when New selected-->
                <Grid Grid.Row="3" Padding="20" x:Name="newAddressForm">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="40" />
                        <RowDefinition Height="20" />
                        <RowDefinition Height="20" />
                        <RowDefinition Height="25" />
                        <RowDefinition Height="20" />
                        <RowDefinition Height="25" />
                        <RowDefinition Height="20" />
                        <RowDefinition Height="25" />
                        <RowDefinition Height="20" />
                    </Grid.RowDefinitions>
                    <Label Grid.Row="0" Text="Billing address" FontAttributes="Bold" FontSize="Default" TextColor="Black" />
                    <Label Text="Address line 1" Grid.Row="1" TextColor="#757575" FontSize="Small" />
                    <Entry Grid.Row="2" x:Name="addressLine1" FontAttributes="Bold" FontSize="Medium" />
                    <Label Text="Address line 2" Grid.Row="3" TextColor="#757575" FontSize="Small" />
                    <Entry Grid.Row="4" x:Name="addressLine2" FontAttributes="Bold" FontSize="Medium" />
                    <Label Text="Address line 3" Grid.Row="5" TextColor="#757575" FontSize="Small" />
                    <Entry Grid.Row="6" x:Name="addressLine3" FontAttributes="Bold" FontSize="Medium" />
                    <Label Text="Postal code" Grid.Row="7" TextColor="#757575" FontSize="Small" />
                    <Picker Grid.Row="8" TextColor="Black" FontSize="Small" x:Name="postalCodeSelector1" ItemDisplayBinding="{Binding PostalDescription}" WidthRequest="100">
                        <Picker.Effects>
                            <effects:DropdownEffect />
                        </Picker.Effects>
                    </Picker>
                </Grid>
            </Grid>
            <StackLayout Grid.Row="1" Orientation="Horizontal" VerticalOptions="End">
                <Button Text="Clear" Style="{x:StaticResource GrayButton}" HorizontalOptions="FillAndExpand" Clicked="ClearBtn_Clicked"/>
                <Button Text="Proceed" HorizontalOptions="FillAndExpand" Clicked="Handle_Clicked" x:Name="proceedBtn" />
            </StackLayout>

            <!--<StackLayout Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" IsVisible="{Binding IsBusy}" BackgroundColor="White" Opacity="1" Orientation="Vertical">
                    <StackLayout Orientation="Vertical" HorizontalOptions="Center" VerticalOptions="CenterAndExpand">
                        <ActivityIndicator Color="#2B428E" IsRunning="true" />
                        <Label x:Name="progressname" Text="Please wait ..." TextColor="#2B428E" VerticalOptions="Center" />
                    </StackLayout>
                </StackLayout>-->
        </Grid>
    </ScrollView>