Articles in this section
Category / Section

How to get the selected item from ListView while using EffectsView within ItemTemplate

1 min read

This section explains how to get selected item from ListView while using SfEffectsView within ItemTemplate.

Consider the use case of showing list of employee names in first page and displaying their corresponding role in second page depending upon the user selection in Xamarin.Forms application as below.

EffectsView

Getting selected item of Listview can be achieved using AnimationCompleted event of SfEffectsView as shown in below code snippet.

XAML

<StackLayout>
        <ListView x:Name="listView"
                         ItemsSource="{Binding Data}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <syncfusion:SfEffectsView TouchDownEffects="Ripple"                                                   AnimationCompleted="OnEffectsViewAnimationCompleted">
                            <Label Text="{Binding Name}"/>
                        </syncfusion:SfEffectsView>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView> </StackLayout>

C#

private void OnEffectsViewAnimationCompleted(object sender, EventArgs e)
        {
            var effectsView = sender as SfEffectsView;
            selectedItem = effectsView.BindingContext as Model;
 
            Navigation.PushAsync(new SecondPage { BindingContext = selectedItem });
        }

 

Note:

When the effects are rendered on direct interaction, the AnimationCompleted event occurs on touchup, and when it is applied programmatically it is triggered immediately on completion of effects.


See also:
How to use effects view in listview(SfListview) xamarin-forms

Also refer our feature tour page to know more about the features available in our effectsview.
 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied