Events in Xamarin Effects View (SfEffectsView)

3 Sep 2020 / 2 minutes to read

AnimationCompleted event

The AnimationCompleted event occurs when the rendered effects have been completed.

<syncEffectsView:SfEffectsView
    TouchDownEffects="Ripple"
    AnimationCompleted="AnimationCompleted">
    ...
</syncEffectsView:SfEffectsView>
public partial class MainPage : ContentPage
{

    public MainPage()
    {
        InitializeComponent();
        var effectsView = new SfEffectsView
        {
            TouchDownEffects = SfEffects.Ripple
        };

        effectsView.AnimationCompleted += AnimationCompleted;
        ...
    }

    private void AnimationCompleted(object sender, EventArgs e)
    {
        ...
    }
}

NOTE

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

NOTE

The AnimationCompleted event is not applicable for SfEffects.Selection.

SelectionChanged event

The SelectionChanged event occurs when SfEffectsView is selected or unselected.

<syncEffectsView:SfEffectsView
    LongPressEffects="Selection"
    SelectionChanged="SelectionChanged"
    TouchDownEffects="None"
    TouchUpEffects="None">
    ...
</syncEffectsView:SfEffectsView>
public partial class MainPage : ContentPage
{

    public MainPage()
    {
        InitializeComponent();
        var effectsView = new SfEffectsView
        {
            LongPressEffects = SfEffects.Selection,
            TouchDownEffects = SfEffects.None,
            TouchUpEffects = SfEffects.None
        };

        effectsView.SelectionChanged += SelectionChanged;
        ...
    }

    private void SelectionChanged(object sender, EventArgs e)
    {
        ...
    }
}

NOTE

The SelectionChanged event triggers both on rendering SfEffects.Selection by direct interaction and on changing the IsSelected property of SfEffectsView.