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.

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.

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.



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.


Another area to look at is the .NET foundation, an opensource consortium of Microsoft and Microsoft partners, that has a ton of opensource .NET code that you can use.


Comments

Popular posts from this blog

How UI Layout Works

Binding Previous Item's data in ItemsControl