I was challenged by Luis Matos to participate in the Xamarin Month of community blogging. The theme this time would be code snippets, and after some thought I figured my subject would be about XAML code snippets, specifically for Xamarin.Forms. So without further ado, here are some code snippets that might save you some time when writing Xamarin.Forms apps.
The snippets are located here. Click “Download ZIP” to download all the snippets in one go.
The first code snippet is for creating a basic ListView with a bindable items source. Use the shortcut
lv and insert the name of your items list and the property (text) that you want to bind the item template to.
Seeing as the CollectionView is the successor of the ListView I also included a snippet for this. It’s pretty similar to the ListView, but the item template is a bit more complex. Use the shortcut
Every time I want a part of a string to have a different formatting I always google the syntax for FormattedString. So why not make it into a snippet? The snippet includes two Span’s with different formatting, with the text for them as parameters. Use it with the shortcut
This short and sweet post was a fun challenge and really opened my eyes for what you can do with code snippets. I’m excited to see what the rest of the community creates. I also encourage you to test out code snippets yourself and see what tedious boilerplate code you can semi-automate.