【问题标题】:How to pass the name of the item in a listview to another form in Xamarin如何将列表视图中的项目名称传递给 Xamarin 中的另一个表单
【发布时间】:2017-07-08 02:15:42
【问题描述】:

我制作了一个 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 页面中写了什么,我在后面的代码中写了什么? 帮助将不胜感激

【问题讨论】:

    标签: xaml xamarin xamarin.forms


    【解决方案1】:

    在你的代码后面

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

    【讨论】:

    • 嘿!.. 这是来自 web api 的项目的动态列表。我需要传递在列表视图上单击的项目的项目代码。你的代码会为此工作吗?
    • 应该的,你试过了吗?
    • 是的,我做到了。不工作。你能建议一些其他的方法吗?
    • “不工作”是什么意思?它具体在哪里失败?事件是否被调用?是否从列表中检索到适当的项目?您的页面堆栈是否已经包含在 NavigationPage 中?
    • 它无法识别 args 关键字并显示错误。我写了这段代码: private async void LstItems_OnItemTapped(object sender, ItemTappedEventArgs e) { var ItemCodeParam = sender as Item; if (ItemCodeParam != null) { var ItemCode = ItemCodeParam.ItemCode; await Navigation.PushAsync(newDetailItemPage(ItemCode.ToString())) 但是这里的导航只是没有发生。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-06
    • 1970-01-01
    相关资源
    最近更新 更多