With an enhanced extensibility framework, Xamarin.Forms is an amazing platform for developing plugins that add cross-platform functionality; however, you can take it a step further by developing custom controls for Xamarin.Forms and packaging them into your very own Control Plugin for Xamarin.Forms. We have had several posts on how to use custom controls in Android, Windows Phone. Circle Image Control PluginMore recently how to create elegant circle images for Xamarin.Forms across all three platforms. Let’s see how we can take this custom control and create a re-distributable control plugin for Xamarin.Forms that you could enter in our holiday plugin for Xamarin contest.

Getting Started

Instead of embedding all of the circle image logic, which we have already finished, into our Xamarin.Forms application you will want to create your own library specifically for the control. This will consist of a Portable Class Library with the CircleImage class and then a class library for iOS, Android, and Windows Phone. I have created some handy templates for Visual Studio to get you started.

An important addition is that in each of your custom renderers you will need to add an initialization method:

public static void Init() { }

This will be familiar to you if you have been creating plugins for Xamarin.Forms, as this insures our control does not getting linked out in the application we add it to.

Adding Bindable Properties

Since your control plugin will be distributed you may want add a few custom bindable properties if it makes sense for your control. For the CircleImage I have added BorderThickness and BorderColor as additional properties that the CircleImage can use.


Packaging the Plugin

After moving all of the logic into this new project you are ready to package your control and publish it on NuGet. Part of the Visual Studio templates that are available will automatically create the nuspec that will need to be uploaded. Here is what the Circle Image’s looks like:

With your control plugin packaged up you are now free to distribute it to everyone via NuGet. Be sure to read the NuGet documentation on how to get started.

Learn More

You can find the Circle Image Control Plugin live on NuGet and the full source code available on GitHub. To find out more information on creating plugins for Xamarin be sure to watch the recording of our live Google+ Hangouts session from last week.

In addition to these resources I have recorded a short getting started with the Plugin for Xamarin templates that enables you to get up and running quickly.