首页 > 解决方案 > Xamarin.Forms:将项目添加到代码中的特定网格行

问题描述

在我的 XAML 中,我有这个网格:

            <Grid Grid.Row="12"  Grid.Column="1" ColumnSpacing="0" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"></RowDefinition>
                    <!--Label-->
                    <RowDefinition Height="3*" ></RowDefinition>
                    <!--ProfilePic-->
                    <RowDefinition Height="*"></RowDefinition>
                    <!-- Btn change-->
                </Grid.RowDefinitions>


                <BoxView BackgroundColor="Purple" Grid.Row="1"></BoxView>

                <ImageButton  
                    Grid.Row="2"
                    x:Name="row_forpic_editProfile"
                    HorizontalOptions="Center"
                    VerticalOptions="Center"
                />

                <Label
                    Grid.Row="0"
                    FontSize="16"
                    TextColor="#272727"
                    VerticalOptions="End"
                    Text="Proilfbild"
                    FontFamily="arial"
                />


                <Button  
                    Grid.Row="2"
                    x:Name="btn_changepic_editprofile"
                    Text="Ändern"
                    HorizontalOptions="Center"
                    VerticalOptions="Center"
                />
            </Grid>

这是这样做的结果:

结果

现在,我想从代码中将图像视图添加到紫色行(即 Grid.Row="1")中,因为我从互联网上下载了一张图片。

我现在如何将我的新图像 (ImageButton) 添加到这个确切的行中?(第 1 行)并让它保持其尺寸(只有图片必须填满容器)。

谢谢你:)

标签: xamarin.forms

解决方案


将 a 添加View到 aGrid

myGrid.Children.Add(view,col,row);

推荐阅读