Events in .NET MAUI SfPullToRefresh

17 Jul 20263 minutes to read

SfPullToRefresh raises three events that you can handle to respond to the user pull gesture, perform the refresh operation, and react when the refresh completes:

  1. Pulling
  2. Refreshing
  3. Refreshed

The Pulling event is raised whenever the swipe gesture starts. It continues to fire until the pull distance exceeds the refresh threshold. When the user releases the pull gesture, the Refreshing event is raised. Perform the refresh operation in the Refreshing handler, and then set SfPullToRefresh.IsRefreshing to false to stop the animation. Once the animation stops, the Refreshed event is raised to indicate completion.

Pulling

The Pulling event is raised whenever you start pulling down on the PullableContent. The handler receives PullingEventArgs, which exposes the following members:

  • Cancel - Set to true to cancel the pulling action based on the Progress value.
  • Progress - Gets the progress completion value (a value between 0 and 1).

The following sample wires up the Pulling event from XAML and reads the Progress value inside the handler:

<syncfusion:SfPullToRefresh x:Name="pullToRefresh" 
                            Pulling="OnPullToRefreshPulling" />
pullToRefresh.Pulling += OnPullToRefreshPulling;

private void OnPullToRefreshPulling(object sender, PullingEventArgs args)
{
    args.Cancel = false;
    var progress = args.Progress; // Read or use the progress value here.
}

NOTE

The Progress value is 0 when the pull starts and approaches 1 as the pull distance increases toward the refresh threshold.

Refreshing

The Refreshing event is raised when the user releases the pull gesture. It is raised only once and continues until IsRefreshing is set to false.

<syncfusion:SfPullToRefresh x:Name="pullToRefresh" 
                            Refreshing="OnPullToRefreshRefreshing" />
pullToRefresh.Refreshing += OnPullToRefreshRefreshing;

private async void OnPullToRefreshRefreshing(object sender, EventArgs args)
{
    pullToRefresh.IsRefreshing = true;
    await Task.Delay(2000);
    pullToRefresh.IsRefreshing = false;
}

Refreshed

The Refreshed event is raised after the Refreshing event completes (that is, after IsRefreshing is set to false). Use this event to perform post-refresh actions such as updating UI state or showing a confirmation.

The following sample wires up the Refreshed event from XAML and handles it in code-behind:

<syncfusion:SfPullToRefresh x:Name="pullToRefresh" 
                            Refreshed="OnPullToRefreshRefreshed" />
pullToRefresh.Refreshed += OnPullToRefreshRefreshed;

private void OnPullToRefreshRefreshed(object sender, EventArgs args)
{
    // Add post-refresh logic here.
}