Xamarin Forms and Syncfusion Xamarin controls
are a powerful combination to get great looking, cross-platform, native
mobile apps while using a mostly shared code base.
In this blog post, we’re going to look at getting started with one of the newer controls to the Syncfusion Xamarin family: the kanban control
First and foremost, all the source code for the examples below can be found here. If you’re not familiar with getting a Xamarin Forms app up and running, have a look at the quick start outlines here.
NuGet packages for Syncfusion controls can be found here; keep in mind you need a license to be able to use them. Luckily, if you’re a hobbyist developer or a company with less than five people, you can get a free Syncfusion community license!
Okay, time to get started. I’m going to assume you already set up a Xamarin Forms wireframe app. If not, check out the quick start above for details on how to get that up and running.
Usually a new Xamarin Forms project adds Windows Phone variant projects. I tend to stick with Universal Windows Platform (UWP) for Windows, since this is generally more actively supported by control suites.
To get access to the Syncfusion NuGets, setup a new NuGet package source that points to the Syncfusion NuGet location.
Add NuGet packages for the Syncfusion kanban control:
Be sure to set the source to the Syncfusion Xamarin NuGet location:
Every project needs to have a reference to the Syncfusion.Xamarin.SfKanban NuGet package. You’ll notice there are Android and iOS variants for the package, too; these are for the specific Xamarin native platforms.
Now for some code.
In the portable library, create a ViewModel class to contain all the items that the cards on the kanban control are going to bind to. A sample of the ViewModel class can be found here.
You need a class that is the model that each kanban card will represent. Syncfusion provides a default called KanbanModel. We’ll use this for now, but you can use your own model classes, too (which I'll cover in another post). Place an ObservableCollection of this model as a property on the ViewModel Class.
Then, add some items to the collection:
Take note of the Category property, as this is going to be used by the control to know in which swim lane to place the kanban card.
Next, create a page that will host the kanban control – sample can be found here
Wire up the BindingContext of the Page to your ViewModel:
Then, attach categories to each column, so the kanban control knows where to place each item template:
This is done in code behind, but you could just as easily bind these to ViewModel properties in XAML.
Be sure to set the Page to the startup page in the Forms App class:
That should be it. Download the source code and give it a test drive.
In my next post I’ll cover:
- Binding cards to custom models
- Creating a custom card template
- Opening up another page when a card gets tapped using a command.
To check out more of Malcolm Jack’s posts, visit his website at: http://inquisitorjax.blogspot.co.za/.