Using Camera along with Gallery in Xamarin Forms

Hi guys. This article gives beginners a very good understanding about how to use Camera & Gallery in Xamain Forms.

Step1: Create the Mobile App (Xamarin Forms) Project

Open VisualStudio 2017    File    New    Project    Choose Cross-Platform Template    Choose MobileApp (Xamarin.Forms )    Name it as CamandDocApp    Click on OK    Choose .NetStandard    Click OK

Step2: Creating a model Gallery.cs

Go to Project CamandDocApp    Right Click    Add Class Gallery.cs


File: Gallery.cs

Model as shown in the following code,
Let consider two properties as Path and Index, as we considering Path as OnpropertyChange .

Step 2: Setting up OnpropertyBase

File: OnpropertyBase.cs

As the Application is creating through MVVM Pattern , we have declared the Model and

Now we have to create the View of Application

Step 3: Setting up Mainpage.Xaml

File: MainPage.Xaml

Step 4:  Installing NuGet Pakages for Camera/Media and Connectivity

  1. Xam.Plugin.Media
  2. Xam.Plugin.Connectivity

Go to Project CamandDocApp   Right Click   ManageNuGet Pakages for Solution


Step 5: Initializing CrossMedia

Go to Project .Android   MainActivity.cs


Step 6: Creating ViewModel

File: GalleryViewModel.cs

Step 7: Setting up Required Permissions

Go to Project .Android   RightClick Properties   Select Android Manifest   Required Permissions



* READ_INPUT_STATE (Please check with below Image)


Step 8: Creating paths to save the Images.

Go to Project .Android    RightClick Resources   Create New Folder “xml”   Create new file in xml folder “file_paths.xml”

File: file_paths.xml


Step 9: Setting up new resource in Android.Manifest.xml

File: Android.Manifest.xml

Add the below code in between the <manifest></manifest>

For the <application> open tag, setup the label with your application Name