As more people are using Xamarin Forms and Xamarin Forms Labs project there are also some issues starting to arise, and a lot of questions on how start using the library. I wanted to start bloging about using the XFLabs project in your applications.
First let’s start as simple as possible, there are some features like IOC that the Labs project uses extensively that i will also explain further. But for now here’s the quickest way to get you started
1 – Install nuget packages :
You can get the bits from the Nuget official source,you just need Xamarin Forms Labs Core to get you started, and you must install the nuget packages in all your projects( main and platforms).
(for now XFLabs is recommended and tested in the pcl version of Xamarin Forms)
2 – Initialize Xamarin Forms Labs in each platform
Xamarin Forms Labs needs to be initialized so the compiler knows what dll’s it has to add to your app.
makes use of Depedency Injection for some features, is recommended that you perform a minimum setup.
On iOS you can just change in your AppDelegate.cs to this:
public partial class AppDelegate : XFormsApplicationDelegate
On Android just change your MainActivity.cs
public class MainActivity : XFormsApplicationDroid
On Windows Phone just add this lines in your App.cs:
var app = new XFormsAppWP();
app.Init(this);
3 . You are done, just use your services or controls.
var mediaPicker = DependencyService.Get<IMediaPicker>();
var result = await mediaPicker.TakePhotoAsync(new CameraMediaStorageOptions { DefaultCamera = CameraDevice.Front, MaxPixelDimension = 400 });
There are some more complex controls that do required some initialization in each plaform, we will cover that in the next post.
Make sure to add any feedback or questions on the comments section.
Leave a Reply