user13397492
user13397492

Reputation: 169

Xamarin.Forms: Add item to certain row of grid from code

in my XAML I have this grid:

            <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>

This is the result of that:

The result

Now, I want to add an imageview into the purple row (which is Grid.Row="1") from code because I downloaded a picture from the internet.

How can I now add my new Image (ImageButton) into this exact row? (row 1) And also have it maintain its dimensions (only the picture must full the container).

thank you:)

Upvotes: 1

Views: 369

Answers (1)

Jason
Jason

Reputation: 89102

to add a View to a Grid

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

Upvotes: 1

Related Questions