Platform specific pages in xamarin forms

Create a Xamarin.Forms Project

Create a Xamarin.Forms page.

<! — ?xml version=”1.0" encoding=”UTF-8"? →`
public partial class CameraPage : ContentPage
{
public CameraPage ()
{
InitializeComponent ();
}
}

Add a Button for the main Page to Open Camera.

<! — ?xml version=”1.0" encoding=”utf-8"? →
<label></label>
<! — ?xml version=”1.0" encoding=”utf-8"? →<label></label><button></button>
async void OnButtonClicked(object sender, EventArgs args)
{
await Navigation.PushAsync(new CameraPage());
}
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new CustomContentPagePage());
}

Creating the Page Renderer on each Platform

Creating the Page Renderer on iOS

[assembly: ExportRenderer(typeof(CameraPage), typeof(CameraPageRenderer))]
namespace CustomContentPage.iOS
{
public class CameraPageRenderer : PageRenderer
{
AVCaptureSession captureSession;
AVCaptureDeviceInput captureDeviceInput;
AVCaptureStillImageOutput stillImageOutput;
UIView liveCameraStream;
UIButton takePhotoButton;
UIButton toggleCameraButton;
UIButton toggleFlashButton;
protected override void OnElementChanged(VisualElementChangedEventArgs e){
base.OnElementChanged(e);
if (e.OldElement != null || Element == null){
return;
}
try{
SetupUserInterface();
SetupEventHandlers();
SetupLiveCameraStream();
AuthorizeCameraUse();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(@” ERROR: “, ex.Message);
}
}
}
}
…….

Creating the Page Renderer on droid

[assembly: ExportRenderer(typeof(CameraPage), typeof(CameraPageRenderer))]
namespace CustomRenderer.Droid
{
public class CameraPageRenderer : PageRenderer, TextureView.ISurfaceTextureListener
{

public CameraPageRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs e) {
base.OnElementChanged(e);
if (e.OldElement != null || Element == null) {
return;
}
try
{
SetupUserInterface();
SetupEventHandlers();
AddView(view);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(@” ERROR: “, ex.Message);
}
}

}
}

--

--

--

VP of Engineering

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Rocket Pool 2.5 — Rolling Beta Launch

“git” commands and usage in Linux

Web Hosting Guide — Essential Facts You Need To Know

AWS SSO and Azure AD for AWS Console/CLI Single Sign-On with ABAC

TrustBase Tinder Program Officially Launched

GemUni INO Launch on KrystalGO: Announcement & Participation Details

Send Personalized Forms

Overcoming AWS CodePipeline’s Design Flaws to Automate Serverless ML Architecture Deployment

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Saman Weerasinghe

Saman Weerasinghe

VP of Engineering

More from Medium

Code Scanning with SonarQube

Handling Concurrency with Async Await in Swift

How to Use Realm Effectively in a Xamarin.Forms App

Realm + Xamarin