5

I am working on xamarin.forms application and I have question that I could not solve.

1) I have multiple Grids one after another that contain button, label and image. Now, on button click I want to change image or rotate it to down. But somehow, I am not able to do it.

My first try was to get parent of button and find image using FindByName method. But FindByName returns null, but I can see grid in parent while debugging.

My second try was to get row of button and find all the controls that are in that row. Because my image is in the same row as button.

My structure is something like this

When I click on arrow(i.e image) it should be changed

My grid works fine but only rotation issue is there.

pubic void OnButtonClicked(object sender, EventArgs e)
{
   var SenderButton = (Button)sender;
   var row = Grid.GetRow(SenderButton); // Here i get row = 0 but dont know how to find other controls on same row.

   Image upimage = SenderButton.Parent.FindByName<Image>("imageExpand");  // imageExpand is my image name in grid.
   upimage.Source = "upimage.png";
}

Here upimage is null.

Thank you very much.

2

1 Answer 1

6

I'm only replying to your first question

you got it right, you can get the value of the attached bindable property Grid.Row using public static int GetRow(BindableObject bindable). Now it's quite easy to filter the grid's Children.

var button = (Button)sender;
var row = Grid.GetRow(button);
var grid = button.Parent as Grid;
//assuming the image is in column 1
var image = grid.Children.Where(c => Grid.GetRow(c) == row && Grid.GetColumn(c)==1);
1
  • 1
    Thank you for answering @Stephane. I will surely try this. Sep 14, 2016 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.