首页 文章

如何将列表视图中的项目名称传递给Xamarin中的另一个表单

提问于
浏览
0

我已经创建了一个xamarin跨平台应用程序,它返回web api中的项目列表 . xaml代码如下所示:

<ViewModels:ItemViewModel/>

</ContentPage.BindingContext>

<ListView ItemsSource="{Binding ItemsList}"

          HasUnevenRows="True" 
          x:Name="lstItems"
         ItemTapped="LstItems_OnItemTapped">



    <ListView.ItemTemplate>

        <DataTemplate>

            <ViewCell>

                <StackLayout Orientation="Horizontal">

                    <Label Text="{Binding ItemCode}" x:Name="lblItemCode" FontSize="Medium" TextColor="Blue"/>
                <Label Text="{Binding ItemDesc}" FontSize="Medium" TextColor="Blue"/>


                </StackLayout>

            </ViewCell>

        </DataTemplate>

    </ListView.ItemTemplate>

</ListView>

我需要将ItemCode作为参数传递给下一页 . 我怎样才能做到这一点?我在xaml页面写什么,我在后面的代码中写了什么?帮助将不胜感激

1 回答

  • 1

    在你的代码背后

    protected void LstItems_OnItemTapped(object sender, ItemTappedEventArgs args) {
      var item = (MyItemClass) args.Item;
      var newpage = new MyNextPage(item.ItemCode);
      Navigation.PushAsync(newpage);
    }
    

相关问题