Complete Camara access using Xamarin forms+xlabs

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.