我有一个包含两个动态操作的视图
以下是我的自定义
label
和 button
的 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