How to use the effects view in Xamarin.Forms' ListView (SfListView)?
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
Download the sample from GitHub.
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 documentation, and 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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!