如何从listview对象发送者xamarin中获取所选项目 [英] How to get selected items from listview object sender xamarin

查看:294
本文介绍了如何从listview对象发送者xamarin中获取所选项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




使用ListView行为,如何获取所选项目或所选行的值/对象?



下面是我尝试的,我得到一个说SelectedItem的属性,但我无法访问它。我错过了什么?



我的尝试:



Hi
Using ListView Behaviors, How do I get values/object of selected item or selected row?

Below is what i tried and I get a property that says "SelectedItem" but i cant access it. What am I missing?

What I have tried:

<ListView.Behaviors>
               <behaviors:EventHandlerBehavior EventName="ItemSelected">
                   <behaviors:InvokeCommandAction Command="{Binding OnItemSelected}"  />
               </behaviors:EventHandlerBehavior>
           </ListView.Behaviors>










//constructor
 public BurialsViewModel()
        {
     _onItemSelected = new Command(OnSelectedItem);
         }









// viewmodel





//viewmodel

ICommand _onItemSelected;
      public ICommand OnItemSelected
      {
          get { return _onItemSelected; }
      }
      void OnSelectedItem(object sender)
        {
           //I need values from sender
        }

推荐答案

很难从有限的代码片段中分辨出来。您似乎没有将 ListView 控件的 ItemsSource 绑定到中的集合视图模型。此外,应该有一个 SelectedItem 属性,您可以绑定到该属性而不按照您的方式执行。 [更新:]以下是如何数据绑定: ListView数据源 - Xamarin [ ^ ]



Xamarin [ ^ ]有一个 tonne您可以学习的资源 [ ^ ]。这是一个提供超出您需要的链接,但将涵盖您想要的内容: Multi - 选择ListView - Xamarin [ ^ ]。另请查看他们的论坛...... [ ^ ]
Hard to tell from the limited code snippets. It appears that you have not bound the ItemsSource of the ListView control to the collection in your ViewModel. Also, there should be a SelectedItem property that you can bind to without doing it the way that you are. [update:] Here is how to databind: ListView Data Sources - Xamarin[^]

Xamarin[^] has a tonne of resources[^] that you can learn from. Here is a link that offers more than what you need but will cover what you want: Multi-select ListView - Xamarin[^]. Also check out their forums...[^]


这篇关于如何从listview对象发送者xamarin中获取所选项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆