Click here to Skip to main content
15,902,198 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
ICommand _onItemSelected;
      public ICommand OnItemSelected
      {
          get { return _onItemSelected; }
      }
      void OnSelectedItem(object sender)
        {
           //I need values from sender
        }
Posted
Updated 12-Nov-17 21:01pm
v2

1 solution

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...[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900