【问题标题】:Xamarin - how to open a new ContentPage in a ListView?Xamarin - 如何在 ListView 中打开新的 ContentPage?
【发布时间】:2017-07-08 00:29:15
【问题描述】:

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

<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

【问题讨论】:

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


    【解决方案1】:
    public void CursoView_ItemSelected(object sender, ItemSelectedEventArgs e)
    {
      // this assumes your current page is already contained in a NavigationPage
      Navigation.PushAsync(new MyNextPage());
    }
    

    【讨论】:

    • 这是我的问题,我的当前页面不是 NavigationPage
    • 您可以简单地将 App.MainPage 替换为新页面,但用户将无法返回
    • 如果您对使用 NavigationPage 不感兴趣,也可以模态显示新页面。
    • 但现在我的清单上有 3 项。我怎样才能让他们根据用户点击的项目推送一个新页面?
    • 使用 e.ItemSelected
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 2018-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多