SelectedItem and TappedCOmmand

Hi,

I have an issue because I want to use the tapped command to show another page and the selecteditem the first time it's tapped is null.

After it works well.

My sflistview ooks like this:

  <listview:SfListView x:Name="catlistView" 
                            
                            HeightRequest="204"
                            IsVisible="{Binding ShowCategories, Mode=TwoWay}"
                            ItemsSource="{Binding WelcomeDtoValue.Categories}" 
                            CurrentItem="{Binding SelectedCategoryMaster}"
                            ItemSize="204" SelectionBackgroundColor="Transparent"
                            SelectionMode="Single" Orientation="Horizontal" ItemSpacing="15"
                            VerticalOptions="Start">
                            <listview:SfListView.Behaviors>
                                <behaviors:EventToCommandBehavior EventName="ItemTapped" Command="{Binding CategorySelectedCommand}"/>
                            </listview:SfListView.Behaviors>

                            <listview:SfListView.ItemTemplate>
                                <DataTemplate>



                                    <local:ElementItemTemplateView 
                                        IsVisible="{Binding Path=WelcomeDtoValue.Categories, Converter={StaticResource lvFull}}"
                                        HeightRequest="204"
                                        ShowFavourite="True"
                                        ShowSelection="False"
                                         />


                                </DataTemplate>
                            </listview:SfListView.ItemTemplate>
                        </listview:SfListView>

When I tap on it the SelectedCategoryMaster the value is null.

The second time I tap on it it works.

It seems that when I tap on the item, the selected item has not been set.

How can I fix this?

PS: I don't want to use SelectionChanged event because if my user comes back to the page, the selection is still done and if it taps on the same viewcell nothing will happen.

And I do not want to set selecteditem to null foreach my views.

Thanks,

2 Replies

AL Alexis May 3, 2020 08:50 PM UTC

Ok I finally found the way.

I use the tappedcommand and define my command in my viewmodel by passing the eventargs.

public ICommand CategorySelectedCommand => AsyncCommand<Syncfusion.ListView.XForms.ItemTappedEventArgs>.Create(CategorySelected);

Thanks!


CS Chandrasekar Sampathkumar Syncfusion Team May 4, 2020 12:24 PM UTC

Hi Alexis, 
Thank you for using Syncfusion products. 
We are glad that reported issue have been resolved at your end. Please let us know if you need any further update. As always we are happy to help you out. 
Regards, 
Chandrasekar Sampathkumar 


Loader.
Up arrow icon