Notification about an empty ListView in Xamarin.Forms

demo

ListView is one of my favourite UI controls available in Xamarin.Forms. It is mostly easy to use and customise. Just bind a collection of data, define the representation of each item and you are done!

However, there is one pitfall which most of the developers tend to ignore – if the bound collection is empty, the ListView will have nothing to show. Depending on the targeting platform it may look ugly or confusing for the end user.

In this blogpost we will check few possible solutions. One solution will be purely implemented on the ViewModel level and the other one will be a reusable ListView control wrapper.

Continue reading “Notification about an empty ListView in Xamarin.Forms”

Advertisements

The ultimate guide to Emojis 🤹‍♂️

 

This slideshow requires JavaScript.

It is very common nowadays to express ourselves by using emojis. Instead of typing few words, we prefer to send one emoji that will express our feelings and emotions. Not sure that the other side will always get what we mean by sending a 🧞 , but that is another story.

In this article we will learn:

  1.  How to use emojis in static content like Labels and Buttons
  2.  How to define and use emoji in XAML only
  3.  How to define and use emoji using C#

Continue reading “The ultimate guide to Emojis 🤹‍♂️”

User input validation in Xamarin.Forms

This slideshow requires JavaScript.

One of the very common tasks that any mobile developer meets is validation of the user input. It can be an email, password complexity, length, not empty or any other sort of input validation. In this article we will try to find an appropriate light-weight and reusable solution, so let’s start!

Continue reading “User input validation in Xamarin.Forms”

Though about optimisation of work with XAML in Xamarin.Forms

What is great about Xamarin.Forms? XAML of course! Especially if you are familiar with it from WPF / Silverlight times. However, the experience with XAML in Xamarin.Forms is totally different. Unfortunately, you will not have such a great intellisense, by default you will have to discover typos in XAML at runtime, no visual editor (yet) and without preview. I have been using VS 2017 on Windows and VS For Mac on macOS, in both cases problems listed above exists.

There are a lot of threads on stackoverflow about these problems and I am repeating myself, again and again, so I decided to write a post about it. I don’t have a magic solution, just a few tricks and a though.

If you are already familiar with XAML and Xamarin.Forms and you don’t care that much about intellisence you can turn on XAML compilation to catch the typos at compile time.
You can enable it at the assembly level, by adding the next line of code to your AssemblyInfo.cs:

[assembly: XamlCompilation(XamlCompilationOptions.Compile);

Or turn XAML compilation at the class level, just the next line above class declaration:

[XamlCompilation (XamlCompilationOptions.Compile)];

More detailed information can be found here.

FYI: If you set the BindingContext inside XAML you may meet this bug.

Remember that all you do in XAML is compiled to code in the end. That means that if the IDE is not working that great with XAML for Xamarin.Forms at this time, you can write everything in plain C#!
Sounds weird, however, all the problems listed above will be solved – except preview. But I find it attractive enough to try. Defining your UI layout in code behind will not violate any of MVVM principles as far as it’s not going to include any business logic.

If you know any other tricks please share.
Have a nice week.