Xamarin - 如何在ListView中打开一个新的ContentPage?

时间:2017-07-07 14:51:49

标签: xamarin xamarin.forms xamarin.forms.listview

我有一个来自我的网络服务的列表,我会这样显示:

<StackLayout HorizontalOptions="FillAndExpand">
    <ListView x:Name="curso" ItemSelected="CursoView_ItemSelected">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <ViewCell.View>
                        <StackLayout Orientation="Horizontal">
                            <StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand">
                                <Label StyleClass="Header" Text="{Binding name}" />
                            </StackLayout>
                        </StackLayout>
                    </ViewCell.View>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</StackLayout>

现在我希望能够点击一个项目并打开一个新的ContentPage

1 个答案:

答案 0 :(得分:2)

public void CursoView_ItemSelected(object sender, ItemSelectedEventArgs e)
{
  // this assumes your current page is already contained in a NavigationPage
  Navigation.PushAsync(new MyNextPage());
}