|
1 | | -# effectsview-listview-xamarin.forms |
2 | | -How to use effects view in ListView (SfListView) Xamarin.Forms ? |
| 1 | +# How to use effects view in ListView (SfListView) Xamarin.Forms ? |
| 2 | +You can integrate the SfEffects in Xamarin.forms SfListView by loading the SfEffectsView as the content of ItemTemplate or SelectedItemTemplate. |
| 3 | + |
| 4 | +**Xaml:** SfEffectsView added as the content of SelectedItemplate with Scale and Selection effects. |
| 5 | +```xml |
| 6 | +<sync:SfListView x:Name="listView" |
| 7 | + AutoFitMode="Height" |
| 8 | + SelectionMode="Single" |
| 9 | + ItemsSource="{Binding BookInfo}"> |
| 10 | + <sync:SfListView.SelectedItemTemplate> |
| 11 | + <DataTemplate> |
| 12 | + <Grid> |
| 13 | + <effects:SfEffectsView x:Name="effectsView" |
| 14 | + SelectionColor="LightSeaGreen" |
| 15 | + FadeOutRipple="True" |
| 16 | + RippleAnimationDuration="1000" |
| 17 | + IsSelected="True"> |
| 18 | + <effects:SfEffectsView.Behaviors> |
| 19 | + <local:Behavior/> |
| 20 | + </effects:SfEffectsView.Behaviors> |
| 21 | + <StackLayout> |
| 22 | + <Label Text="{Binding BookName}" FontSize="21" |
| 23 | + FontAttributes="Bold"/> |
| 24 | + <Label Grid.Row="1" Text="{Binding BookDescription}" |
| 25 | + FontSize="15"/> |
| 26 | + </StackLayout> |
| 27 | + </effects:SfEffectsView> |
| 28 | + </Grid> |
| 29 | + </DataTemplate> |
| 30 | + </sync:SfListView.SelectedItemTemplate> |
| 31 | +</sync:SfListView> |
| 32 | +``` |
| 33 | +**C#:** Programmatically apply effects to the SelectedItem. |
| 34 | +``` C# |
| 35 | +public class Behavior : Behavior<SfEffectsView> |
| 36 | +{ |
| 37 | + protected override void OnAttachedTo(SfEffectsView bindable) |
| 38 | + { |
| 39 | + bindable.SelectionChanged += Bindable_SelectionChanged; |
| 40 | + base.OnAttachedTo(bindable); |
| 41 | + } |
| 42 | + |
| 43 | + private void Bindable_SelectionChanged(object sender, EventArgs e) |
| 44 | + { |
| 45 | + Device.BeginInvokeOnMainThread(() => |
| 46 | + { |
| 47 | + var effectsView = sender as SfEffectsView; |
| 48 | + effectsView.ScaleFactor = 0.85; |
| 49 | + effectsView.ApplyEffects(SfEffects.Scale); |
| 50 | + }); |
| 51 | + } |
| 52 | + protected override void OnDetachingFrom(SfEffectsView bindable) |
| 53 | + { |
| 54 | + bindable.SelectionChanged -= Bindable_SelectionChanged; |
| 55 | + base.OnDetachingFrom(bindable); |
| 56 | + } |
| 57 | +} |
| 58 | +``` |
0 commit comments