PullToRefresh
PullToRefresh adds the familiar mobile gesture to any Wisej.NET scrollable container, such as a Panel, a FlowLayoutPanel, a FlexLayoutPanel or a UserControl. When the container is scrolled to the top and the user drags it down, a loader panel slides in above the content. When the user lets go, the server receives a Refresh event, where you reload the data.
The gesture is built on pointer events, so it works with a finger on touch devices and with the mouse on the desktop.
Installation
Add the Wisej-4-PullToRefresh package to your Wisej.NET project:
dotnet add package Wisej-4-PullToRefresh
The package targets .NET Framework 4.8 and .NET 8 or later (including the -windows, Android, iOS and Mac Catalyst targets). After a rebuild, PullToRefresh shows up in the Visual Studio toolbox as a component.
Getting started
Create a PullToRefresh, or drop one on the page from the toolbox, and enable it for each container with SetPullToRefresh. There's no per-control property in the designer, so this is always done in code:
- C#
- VB.NET
using Wisej.Web.Ext.PullToRefresh;
public partial class Page1 : Page
{
private readonly PullToRefresh pullToRefresh1 = new PullToRefresh();
public Page1()
{
InitializeComponent();
this.pullToRefresh1.DropDownHeight = 80;
this.pullToRefresh1.BackColor = Color.WhiteSmoke;
this.pullToRefresh1.SetPullToRefresh(this.panelNews, true);
this.pullToRefresh1.Refresh += pullToRefresh1_Refresh;
}
private void pullToRefresh1_Refresh(object sender, EventArgs e)
{
// sender is the container the user pulled.
var panel = (Panel)sender;
LoadLatestNews(panel);
}
}
Imports Wisej.Web.Ext.PullToRefresh
Public Class Page1
Inherits Page
Private WithEvents pullToRefresh1 As New PullToRefresh()
Public Sub New()
InitializeComponent()
Me.pullToRefresh1.DropDownHeight = 80
Me.pullToRefresh1.BackColor = Color.WhiteSmoke
Me.pullToRefresh1.SetPullToRefresh(Me.PanelNews, True)
End Sub
Private Sub pullToRefresh1_Refresh(sender As Object, e As EventArgs) Handles pullToRefresh1.Refresh
' sender is the container the user pulled.
Dim panel = DirectCast(sender, Panel)
LoadLatestNews(panel)
End Sub
End Class
One PullToRefresh can serve several containers. The sender of Refresh tells you which one was pulled.
The pull is only recognized while the container is scrolled to the very top. For the effect to feel natural, the container should be able to scroll (e.g. AutoScroll = true) and hold enough content to need it, as in a list of cards or a news feed.
Properties and methods
| Member | Default | What it does |
|---|---|---|
SetPullToRefresh(control, enabled) | — | Turns the gesture on or off for a ScrollableControl. A control that hasn't been created yet is registered as soon as it is. |
GetPullToRefresh(control) | false | Whether the gesture is on for that control. |
Clear() | — | Removes the gesture from every registered control. |
DropDownHeight | 50 | Height of the loader panel in pixels, which is also how far the content can be dragged down. The loader image is scaled to DropDownHeight - 20. |
BackColor | Transparent | Background of the loader panel. |
ImageSource | resource.wx/loader.svg | The loader image: a URL, an application-relative path or a theme image name. |
The extender centers the loader image but doesn't animate it. For a spinning effect, use an animated SVG or GIF, e.g. this.pullToRefresh1.ImageSource = "Images/spinner.gif";.
Registered controls are unregistered automatically when they're disposed.
Events
| Event | When |
|---|---|
Refresh | The user completes the pull gesture on a registered control. sender is that control. |
If reloading takes a while, show progress while you work, e.g. set panel.ShowLoader = true at the start of the handler and back to false at the end. For long work, move it to a background task and push the result with Application.Update.
API reference
PullToRefresh- The whole
Wisej.Web.Ext.PullToRefreshnamespace