Using Shared Components In Xamarin Forms

Xamarin has several cross-platform libraries available for you to use so that we have unified API for accessing platform specific features from iOS, Windows Phone, and Android. These are all open source and available via GitHub which you can then use or modify to whatever you like.
Xamarin
There are several components that Xamarin supports. The first is "Xamarin Social" which provides some social networking capabilities to your application. It has support for posting to Facebook and Twitter, to name a few.
Xamarin

We also have Xamarin.Auth which is used for OAuth. It supports securely connecting to the web services. And then, we have the Xamarin.Mobile component which has Location, Camera, and Photo access.

Xamarin

As an example, here, we have some code to take a picture using Xamarin.Mobile. This code works on iOS, Android, as well as Windows apps. The media picker that you see here provides access to the photo as a file or as a stream. So then, you can load it into whatever the platform specific representation of an image might be. Now, you could, of course, write this code using platform-specific APIs but then you have to write it three times separately. And in fact, you might still choose to use the native API if you need some special capability that's unique to the platform, but more often than not, you just want to take a photo.
Xamarin

Another area to look at is the .NET foundation, an open source consortium of Microsoft and Microsoft partners, that has a ton of opensource .NET code that you can use.
Xamarin
Another great place to look at is a GitHub. Xamarin maintains a list of opensource plugins github/xamarin/plugins. These have all been produced by different authors and they're not officially supported by Xamarin; but each provides an abstraction over some specific feature with implementations for each platform. So, you can access that feature from shared code. All of these are open source and most of them can be used either in source form or as a binary which you can add using NuGet.

Xamarin

You likely have already used NuGET if you've done any Microsoft development. Nuget is a package manager for .NET development that supports downloading and installing both, binary and source, elements in project. There's a large public repository at www.nuget.org which you can use to search for available components by name or by functionality. You can also create your own private repositories using a folder network share or even a web URL.

Xamarin

You can add, remove, and update components directly from your IDE. It's supported in both, Visual Studio and Xamarin Studio, through the reference notes on the project.

Xamarin

It also supports auto package restore automatically which means you don't need to include the NuGet packages directly in your source control. And Microsoft is moving towards it as their primary vehicle of code updates and component distribution, including frameworks such as ASP.NET and Xamarin.Forms.

Xamarin

Another option for Xamarin specific components is the Xamarin Components Store. This is an older distribution channel that was created before NuGet. However, there are still a lot of great components here.

Xamarin

It's accessible through the Components folder in each of your projects. It supports a commercial pricing model. And, Xamarin manages this store so that every component is validated and tested.

Xamarin

You can use either NuGet or the Component Store and often components are published in both. But generally, you should prefer nuGet because it's fully supported by both, Microsoft and the Xamarin tools.
Xamarin


Similar Articles