Xamarin.Forms.Behaviors icon indicating copy to clipboard operation
Xamarin.Forms.Behaviors copied to clipboard

ListView ItemSelected

Open amccorma opened this issue 10 years ago • 1 comments

The listView ItemSelected Command fires, but the CommandParameter are not set to the item in the ListView. If I change {Binding Model} it gets the data in the listview, but I would like the item that is Selected. Is this Supported?

<common:BasePage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:b="clr-namespace:Xamarin.Behaviors;assembly=Xamarin.Behaviors" x:Class="Mobile.Forms.Release.Pages.VoterToolkitPage" x:Name="VoterPage"> common:BasePage.Content <StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Padding="10,10"> <StackLayout> <ctrl:MyFrameBorder InnerBackgroundColor="White" BorderColor="Black" HeightRequest="80" IsVisible="{Binding CapWHeader}"> ctrl:MyFrameBorder.View <StackLayout
HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand" Padding="5, 5"> <Label Text="{Binding CapWizText}"></Label> <Label Text="{Binding CapWizLink}"></Label> </StackLayout> /ctrl:MyFrameBorder.View /ctrl:MyFrameBorder </StackLayout> <StackLayout> <ListView IsGroupingEnabled="true" HasUnevenRows="true" ItemsSource="{Binding Model}" x:Name="lst1"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <ViewCell.View> <StackLayout Padding="0, 0, 0, 0"> <StackLayout Padding="0, 2"> <Label Text="{Binding StringFormat}"> </Label> </StackLayout> </StackLayout> </ViewCell.View> </ViewCell> </DataTemplate> </ListView.ItemTemplate> <ListView.GroupHeaderTemplate> <DataTemplate> <ViewCell> <ViewCell.View> <StackLayout VerticalOptions="End" HorizontalOptions="Start"> <Label Text="{Binding Label}" TextColor="Black" Font="Bold, Large" XAlign="Start" YAlign="End" HeightRequest="40"> </Label> </StackLayout> </ViewCell.View> </ViewCell> </DataTemplate> </ListView.GroupHeaderTemplate> <b:Interaction.Behaviors> <b:BehaviorCollection>
<b:EventToCommand BindingContext="{x:Reference lst1}" CommandNameContext="{b:RelativeContext VoterPage}" EventName="ItemSelected" CommandName="VoterItemTapped" CommandParameter="{Binding StringFormat}" /> /b:BehaviorCollection /b:Interaction.Behaviors </ListView> </StackLayout> </StackLayout> /common:BasePage.Content /common:BasePage

amccorma avatar Nov 17 '14 18:11 amccorma

You can bind ListView's SelectedItem property to the ViewModel using Mode=TwoWay or, if you want to use ItemTapped event you can try this example: http://pastebin.com/Hx3T8qVQ

corcav avatar Nov 17 '14 21:11 corcav