How to add button in other cell? I tried to do that but is not working. Thanks for help. My cod:
var button = new Image { Source = "page.png"};
button.GestureRecognizers.Add(new TapGestureRecognizer
{
Command = new Command((async sender =>
{
await Navigation.PushAsync(new page());
}))
});
var grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = 200 });
grid.Children.Add(new Label { Text = "00"}, 0, 0);
grid.Children.Add(new Label { Text = "01"}, 0, 1);
grid.Children.Add(new Label { Text = "02"}, 0, 2);
grid.Children.Add(button, 1, 0); //this is not visible
grid.Children.Add(button, 1, 1); //this is not visible
grid.Children.Add(button, 1, 2);
grid.Children.Add(new Label { Text = "20"}, 2, 0);
grid.Children.Add(new Label { Text = "21"}, 2, 1);
grid.Children.Add(new Label { Text = "22"}, 2, 2);
You can't use the same instance of a control in multiple cells. You need to create a new instance for each Cell you want it to appear in.
var button1 = new Image { Source = "page.png"};
var button2 = new Image { Source = "page.png"};
var button3 = new Image { Source = "page.png"};
// add gesture recognizers to each instance
grid.Children.Add(button1, 1, 0);
grid.Children.Add(button2, 1, 1);
grid.Children.Add(button3, 1, 2);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.