Articles in this section
Category / Section

How to use the effects view in Xamarin.Forms' ListView (SfListView)?

3 mins read

You can integrate the SfEffects in Xamarin.forms SfListView by loading the SfEffectsView as the content of ItemTemplate or SelectedItemTemplate.

Xaml: SfEffectsView added as the content of SelectedItemplate with Scale and Selection effects.

<sync:SfListView x:Name="listView"
                AutoFitMode="Height" 
                SelectionMode="Single"
                ItemsSource="{Binding BookInfo}">
    <sync:SfListView.SelectedItemTemplate>
        <DataTemplate>
            <Grid>
                <effects:SfEffectsView x:Name="effectsView"
                                       SelectionColor="LightSeaGreen"
                                       FadeOutRipple="True"
                                       RippleAnimationDuration="1000"
                                       IsSelected="True">
                    <effects:SfEffectsView.Behaviors>
                        <local:Behavior/>
                    </effects:SfEffectsView.Behaviors>
                    <StackLayout>
                        <Label Text="{Binding BookName}" FontSize="21"
                               FontAttributes="Bold"/>
                        <Label Grid.Row="1" Text="{Binding BookDescription}"
                               FontSize="15"/>
                    </StackLayout>
                </effects:SfEffectsView>
            </Grid>
        </DataTemplate>
    </sync:SfListView.SelectedItemTemplate>
</sync:SfListView>

 

C#: Programmatically apply effects to the SelectedItem.

 

public class Behavior : Behavior<SfEffectsView>
{
    protected override void OnAttachedTo(SfEffectsView bindable)
    {
        bindable.SelectionChanged += Bindable_SelectionChanged;
        base.OnAttachedTo(bindable);
    }
 
    private void Bindable_SelectionChanged(object sender, EventArgs e)
    {
        Device.BeginInvokeOnMainThread(() =>
        {
            var effectsView = sender as SfEffectsView;
            effectsView.ScaleFactor = 0.85;
            effectsView.ApplyEffects(SfEffects.Scale);
        });
    }
    protected override void OnDetachingFrom(SfEffectsView bindable)
    {
        bindable.SelectionChanged -= Bindable_SelectionChanged;
        base.OnDetachingFrom(bindable);
    }
}

 

Output

 

EffectsView in Xamarin

 

Download the sample from GitHub.

 

Conclusion

I hope you enjoyed learning about how to use the effects view in Xamarin.Forms' ListView (SfListView).

You can refer to our Xamarin Effects View feature tour page to know about its other groundbreaking feature representations and documentationand how to quickly get started for configuration specifications.

For current customers, you can check out our Xamarin components from the License and Downloads
page. If you are new to Syncfusion, you can try our 30-day 
free trial
to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (1)
Please  to leave a comment
DE
Deleted_1585477

Hi,

can we show the animation even if we select the items in codeBehind by adding them to listView? --> listView.SelectedItems.Add(item); The animation will not show in my case. Only the color and style changes are setted.

Thanks!

Maria

SS
Sridevi Sivakumar

Hi Oliver Neis,

We have checked the reported query and we would like to inform you that the effect is applying properly when we selected the item through code behind.

We have prepared a sample and video for your requirement, please have a sample from the below link

Sample link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Sample602740335

Video link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Video133525592

Regards, Sridevi S.

Access denied
Access denied