我有listview
有兩個視圖動態操作label
和button
,我試圖訪問按鈕點擊進入按鈕點擊的詳細信息頁面。下面如何訪問按鈕單擊Xamarin.Forms中的listview數據模板?
是我的自定義ViewCell
protected override async void OnAppearing()
{
listClass.ItemsSource = list;
listClass.ItemTemplate = new DataTemplate(typeof(ItemTemplateViewCell));
}
public class ItemTemplateViewCell : ViewCell
{
Label NameLbl = new Label();
StackLayout sLayout = new StackLayout();
Button btnViewcell = new Button {Text = "Show class details"};
public ItemTemplateViewCell()
{
NameLbl.SetBinding(Label.TextProperty, "Name");
sLayout.Children.Add(NameLbl);
btnViewcell.Clicked += (s, e) =>
{
// Navigation.PushAsync(new Home()); //I can not using this line
// does not exist in the current context, why cant i navigate to
// another page from inside datatemplate in List view
};
sLayout.Children.Add(btnViewcell);
this.View = sLayout;
}
}
我希望背後的註釋'Navigation.PushAsync(...'是在你的實際代碼中的一行?請把它放在一行,然後在這裏,因爲這確實在編碼上有很大的區別 – Kyra