Checking the new Checkbox in Xamarin.Forms 4.1 and overviewing InputKit control
Tags: xamarin, controls, ui, xamarinforms
Published: 2019-10-13 19:16:16

---
title: Checking the new Checkbox in Xamarin.Forms 4.1 and overviewing InputKit control
published: true
date: 2019-07-05 22:10:23 UTC
tags: Xamarin,controls,ui,Xamarin.Forms
canonical_url: https://blog.torib.io/2019/07/05/checking-the-new-checkbox-in-xamarin-forms-4-1-and-overviewing-inputkit-control/
---

_Pun very much intended…_

With the release of Xamarin.Forms 4.1 arrives a new [Checkbox control](https://docs.microsoft.com/en-us/xamarin/android/user-interface/controls/buttons/check-box). Here is what it looks like:

![](https://blog.torib.io/wp-content/uploads/2019/07/Screen-Shot-2019-07-05-at-4.12.25-PM.png)<figcaption>Image was taken straight from the documentation <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/checkbox">https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/checkbox</a></figcaption>

Here are the two ways to instantiate it in XAML and C#

<script src="https://gist.github.com/eatskolnikov/748a6e7cc9fcb03f9d4eecb50a2b2ff9.js"></script>

The Checkbox has a bindable property for the checked status (IsChecked) and you can handle the **CheckedChanged** event too.

<script src="https://gist.github.com/eatskolnikov/d6947dbb44b526cea76b879c1abe1064.js"></script>
#### A little thing

The control has a rounded shape on iOS if you want it to have a square shape you can use the [Visual API](https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/visual/).

For now, the CheckBox control doesn’t include a Text property and it doesn’t render a Label next to it, to achieve this you would need to explicitly include a Label control and align it next to it.

<script src="https://gist.github.com/eatskolnikov/511af2127ecccb298f7a45fd2dd12cd7.js"></script>

The result looks like this:

![](https://blog.torib.io/wp-content/uploads/2019/07/Screen-Shot-2019-07-05-at-6.11.48-PM.png)<figcaption>On the left side is the iOS version on the right side the Android one</figcaption>

### Other options

If you’re working on a legacy project or, for whatever reason, you are not able to update to Xamarin.Forms 4.1 but you are still looking to include a CheckBox here are a couple of options for you:

1. **Use the** [**Switch**](https://docs.microsoft.com/en-us/xamarin/android/user-interface/controls/switch) **control.** In a practical/functional way, this is pretty much the same as a CheckBox in that you can manage on/off (true/false) states. The UI is certainly not that of a Checkbox but if all you need is the functionality this will be just fine.
2. **Use the [Xamarin.Forms.InputKit](https://github.com/enisn/Xamarin.Forms.InputKit) library**. It has been out for a while now so the team has had the time to include some neat features, like being able to set the label for the control, radio buttons and set a custom check icon to name a few.

####   
Using the Xamarin.Forms.InputKit library

Like most third-party libraries in the Xamarin Ecosystem, it is very easy to set up and gives you access to a healthy variety of controls. We will focus on the Checkbox functionality, for now. I may write about the complete library on a later entry.

To set up the library just do as follows:

- Include the **Xamarin.Forms.InputKit** NuGet package in all your projects.
- Initialize it in your target projects by calling **Plugin.InputKit.Platforms.iOS.Config.Init();** or **Plugin.InputKit.Platforms.Droid.Config.Init(this, savedInstanceState);** accordingly.
- Reference the library’s namespace in your XAML **xmlns:input=”clr-namespace:Plugin.InputKit.Shared.Controls;assembly=Plugin.InputKit”**.
- Prepend the input namespace to the controls you want to include.

To create a checkbox you would write something like this:

<script src="https://gist.github.com/eatskolnikov/c9d627ca753a40467e32e1b016aae121.js"></script>
- ![](https://blog.torib.io/wp-content/uploads/2019/07/Screen-Shot-2019-07-05-at-4.57.07-PM.png)

- ![](https://blog.torib.io/wp-content/uploads/2019/07/Screen-Shot-2019-07-05-at-4.57.17-PM.png)

Same as the new Xamarin.Forms Checkbox control, the InputKit one includes a bindable property for the checked state called **IsChecked** and you can listen to the checked status changed status either with the event handler **CheckChanged** or with the command **CheckChangedCommand**.

As mentioned before, this library has been around for some time some it includes a few more things than the new Xamarin Forms native Checkbox like the ability to include the checkbox’s label text and the type of checkbox you want to render. These are the different types:

![](https://blog.torib.io/wp-content/uploads/2019/07/Screen-Shot-2019-07-05-at-4.02.53-PM.png)<figcaption>Image was taken straight from the repository <a href="https://github.com/enisn/Xamarin.Forms.InputKit">https://github.com/enisn/Xamarin.Forms.InputKit</a></figcaption>

I wrote a sample project here if you want to check it out [https://github.com/eatskolnikov/CheckBoxSample](https://github.com/eatskolnikov/CheckBoxSample)

And that’s all folks, as always, I hope this information has been of use to you and if you liked it feel free to share it with your peers and check the other posts. Thanks, Bye!

The post [Checking the new Checkbox in Xamarin.Forms 4.1 and overviewing InputKit control](https://blog.torib.io/2019/07/05/checking-the-new-checkbox-in-xamarin-forms-4-1-and-overviewing-inputkit-control/) appeared first on [Enmanuel Toribio](https://blog.torib.io).