So our next post is going to be fast and easy, how can you add Pull to Refresh to your Xamarin.Forms apps? These 2 steps are going to show you how:
This small tutorial implies that you already have a running project if you don't please download the sample at the end of this page.
If you are using XAML you need to add this lines of code to your ListView:
If you are using code behind you can do the same inside your Page using:
2.- So as you can see we are binding our ListView Refresh Command to a property called
RefreshCommand this is where the magic happens... Inside your
ViewModel add a new property command like this:
And don't forget to initialize your command inside the ViewModel constructor like this:
_refreshCommand = new Command(RefreshList);
In this example our method that is going to be called on our Pull to Refresh command is called
RefreshList inside this method you can do what ever you need in this case is an async function that is going to refresh our list:
Run the project and... there you go, your LisView will have a pull to refresh event to be triggered:
As you can see there is not much complicated stuff while including this amazing event to your apps, nevertheless let me know any comments or questions.
Subscribe to My two cents on Xamarin
Get the latest posts delivered right to your inbox