我有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