1. Install NuGet
Xamarin.Forms
Xlabs.forms
2. MainActivity.cs (Android)
public class Mainactivity:xformsapplicationdroid {//<summary>//Called when [create]. </summary>//<param name= "bundle" >the bundle.</param> protected override void ONCR Eate (Bundle bundle) {base. OnCreate (bundle); if (! Resolver.isset) {this. SETIOC (); } else {var app = resolver.resolve<ixformsapp> () as Ixformsapp<xformsapplic ationdroid>; if (app! = null) app. AppContext = this; } Xamarin.Forms.Forms.Init (this, bundle); This. Loadapplication (New App ()); }///<summary>//sets the IoC. </summary> private void Setioc () {var resolvercontainer = new Simplecontainer (); var app = new Xformsappdroid (); App. Init (this); Resolvercontainer.register<idevice>(t = androiddevice.currentdevice). Register<imediapicker, mediapicker> (); Resolver.setresolver (Resolvercontainer.getresolver ()); } }
3. ViewModel (Portable)
CamaraViewModel.cs
Take it from here.
Https://github.com/XLabs/Xamarin-Forms-Labs/blob/master/Samples/XLabs.Sample/ViewModel/CameraViewModel.cs
4. View (Portable)
Photo.xaml
<?xml version= "1.0" encoding= "Utf-8"? ><contentpage xmlns= "Http://xamarin.com/schemas/2014/forms" xml ns:x= "Http://schemas.microsoft.com/winfx/2009/xaml" xmlns:viewmodels= "Clr-namespace:photosample.viewmodels;ass Embly=photosample "x:class=" PhotoSample.Views.Photo "> <ContentPage.BindingContext> <viewmodels : Cameraviewmodel/> </ContentPage.BindingContext> <StackLayout> <button text= "Take Picture" Command = "{Binding Takepicturecommand}"/> <button text= "Select Image from Picture Library" command= "{Binding selectpictu Recommand} "/> <button text=" Select Video from the picture Library "command=" {Binding selectvideocommand} "/> <image source= "{Binding ImageSource}" verticaloptions= "Centerandexpand"/> <entry text= "{Binding VideoInfo}" verticaloptions= "Centerandexpand"/> </StackLayout></ContentPage>
App.cs (Portable) Initial view points to photo
MainPage = new Photo ();
Complete Camara access using Xamarin forms+xlabs