Adding Loader/Progress to your xamarin App using Postsharp.

Ahmed Fouad

Jakob Nielsen’s 10 heuristics for design are considered the bible of user experience, they are designated “heuristics” since they are wide general guidelines and not explicit ease of use rules.

If you are interested to see some examples of Nielsen heuristics in mobile apps Bharti Bhagtani has an awesome post showing them.

In this series i will show how you can satisfy all Nielsen 10 heuristics by investing maximum 10 minutes extra in your application.

1- Visibility of system status

In a lot of cases you will have to deal with async methods that will take quite time for action completeness. In this case you must show the user a progress indicator to tell him that his action is in progress.

We will do this simply by implementing a Progress Advice and use it on the async methods in our viewmodel.

And you can use it simply by decorating the async method

If the method is not taking any Progress<Int> or cancellation Token parameter , the progress will be indeterminate and without a cancellation button.

[ShowProgress("Downloading")]
public async Task TestLoader()
{
await Task.Delay(1000);
}

If the method use has a IProgress<int> parameter the progress will be determined and you can report from your method the effective progress.

make sure the progress parameter has default value null as it will be injected from the the aspect.

[ShowProgress("Downloading")]
public async Task TestLoader(IProgress<int> progress=null)
{
await Task.Delay(1000);
progress.Report(50);
await Task.Delay(1000);
progress.Report(1000);
}

and you can also use a CancellationToken to allow the user to cancel the operation.

[ShowProgress("Downloading")]
public async Task TestLoader(CancellationToken cancellationToken=default(CancellationToken))
{
await Task.Delay(1000,cancellationToken);
}

you will need to get Postsharp installed in your machine and this 2 nuggets

Ahmed Fouad

Written by

Hello, I’m Ahmed. I’m a software engineer living in Vienna, Austria. I am a fan of technology, web development, and programming. I’m also interested in xamarin

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade