0

I have a question. I added an Image to my Grid, but now I want to change the row of the image from 0 to 2. I already gave my image a name: "imgColorPicker" How can I do this using C#?

Here is my code:

<Grid VerticalOptions="Center" x:Name="MainGrid">
    <Grid.RowDefinitions>
        <RowDefinition Height="50" />
        <RowDefinition Height="*" />
        <RowDefinition Height="50" />
    </Grid.RowDefinitions>

    <Image Grid.Row="0" Source="Color_Picker" x:Name="imgColorPicker"/>
</Grid>

Any ideas?

A. Vreeswijk
  • 822
  • 1
  • 19
  • 57

3 Answers3

3

remove it then re-add it in the correct cell

MainGrid.Children.Remove(imgColorPicker);
MainGrid.Children.Add(imgColorPicker, col, row);
Jason
  • 86,222
  • 15
  • 131
  • 146
0

There isn't any condition to change the row index? If there is, you can change it with a trigger or value converter. You can achive that in the code behind too, check this how-to-set-grid-row-and-column-positions-programmatically

0

The following should solve your problem:

Grid.SetRow(imgColorPicker, 2);