Book Image

Xamarin Cross-Platform Development Cookbook

By : George Taskos
Book Image

Xamarin Cross-Platform Development Cookbook

By: George Taskos

Overview of this book

<p>You can create native mobile applications using the Xamarin Forms platform for the three major platforms iOS, Android, and Windows Phone. The advantage of this is sharing as much code as you can, such as the UI, business logic, data models, SQLite data access, HTTP data access, and file storage across the three major platforms.</p> <p>This book provide recipes on how to create an architecture that will be maintainable, extendable, use Xamarin Forms plugins to boost productivity, customize your views per platforms, and use platform-specific implementations at runtime.</p> <p>We start with a simple creation of a Xamarin Forms solution with the three major platforms. We will then jump to XAML recipes and you will learn how to create a tabbed application page, and customize the style and behavior of views for each platform. Moving on, you will acquire more advanced knowledge and techniques while implementing views and pages for each platform and also calling native UI screens such as the native camera page.</p> <p>Further on, we demonstrate the power of architecting a cross-platform solution and how to share code between platforms, create abstractions, and inject platform-specific implementations. Next, you will utilize and access hardware features that vary from platform to platform with cross-platform techniques. Well then show you the power of databinding offered by Xamarin Forms and how you can create bindable models and use them in XAML. You will learn how to handle user interactions with the device and take actions in particular events.</p> <p>With all the work done and your application ready, you will master the steps of getting the app ready and publishing it in the app store.</p>
Table of Contents (18 chapters)
Xamarin Cross-Platform Development Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Taking an in-app photo with the native camera page


This chapter is all about mix and match cross-platform UI and native platform UI. In the last recipe of the chapter, we will create a Xamarin.Forms solution and utilize the native APIs of each platform to capture a photo.

How to do it…

  1. As usual, create a Xamarin.Forms project in Visual Studio using a PCL class library for our core shared project. Give it the name XamFormsInAppPhoto.

  2. Right-click our core PCL project and Add | Class…, name it InAppCameraPage, and click Add.

  3. Make it a ContentPage subclass.

  4. Go to the App.cs constructor and replace the code in the MainPage property assignment with a new InAppCameraPage instance.

    MainPage = new InAppCameraPage();

That's all we need for our core project setup. We'll move now to the Android platform.

  1. To get access in the related camera APIs of Android, we will need a custom PageRenderer for each platform. Right-click the Android project, Add | Class…, name the class InAppCameraPageRenderer, and click Add...