2016-09-29 74 views
0

如何在其他單元格中添加按鈕? 我試圖做到這一點,但沒有工作。感謝幫助。我的鱈魚:其他單元格中的按鈕:Xamarin.Forms

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); 
+0

您不能在多個單元中使用同一個控件實例。您需要爲每個希望顯示的單元格創建一個新實例。 – Jason

+0

如何做到這一點? – user5734658

回答

0

您不能在多個單元中使用同一個控件實例。您需要爲每個想要它出現的單元格創建一個新實例。

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); 
相關問題