Page 29 - MSDN Magazine, August 2017
P. 29

Figure 9 Native Control Namespace Declarations
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:ios="clr-namespace:UIKit;assembly=Xamarin.iOS;targetPlatform=iOS" xmlns:androidWidget="clr-namespace:Android.Widget;assembly=
Mono.Android;targetPlatform=Android" xmlns:formsandroid="clr-namespace:Xamarin.Forms;assembly= Xamarin.Forms.Platform.Android;targetPlatform=Android"
xmlns:win="clr-namespace:Windows.UI.Xaml.Controls;assembly=Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime;targetPlatform=Windows"
x:Class="b4ufly.NativeView" > <ContentPage.Content> </ContentPage.Content>
</ContentPage>
Those are the three approaches to Xamarin.Forms custom- ization: custom renderers, effects and native view declaration. Custom renderer is a heavyweight option offering a lot of flexi- bility, while effects provides a surgical approach to customization. Native view declaration is the nuclear option, circumventing Xamarin.Forms entirely.
Wrapping Up
You’ll eventually need more from Xamarin.Forms than it gives you out-of-the-box, just like I did with B4UFLY. When complex tasks or designs are required by Xamarin.Forms, virtually anything is possible using Xamarin.Forms customization. Customization pro- vides access to the lower-level, platform-specific, screen-rendering classes called “renderers,” which use platform-specific controls to create all Xamarin.Forms screens. Any Xamarin.Forms screen can be broken into platform-specific screens, classes, controls and properties using this approach.
A lighter-weight approach is to use effects to access platform- specific properties and events. You can also use entire native controls on your Xamarin.Forms pages using native view declaration.
This means that you can write a Xamarin.Forms page or app and customize it by platform. Use customization sparingly, or risk a fragmented UI code base that probably should have been written entirely as a platform-specific UI. Used judiciously, cus- tomization can turn your basic, lackluster product into a versatile, unique, popular app.
In B4UFLY, the FAA’s investment in Xamarin.Forms continues to pay off because of the many ongoing enhancements that are generic to the many cross-platform text-based pages. The platform- specific map page contains some cross-platform elements, but much of that page requires platform-specific customization. This Xamarin.Forms architecture is extensible and development times and costs are lower because of it; the significant code reuse is practical and elegant. n
Dan Hermes is a Xamarin MVP, a Microsoft MVP, and author of “Xamarin Mobile Application Development.” He is principal of Lexicon Systems, a Boston- based consultancy building award-winning mobile apps and helping companies build their own successful apps. Follow his blog at mobilecsharpcafe.com, on Twitter: @danhermes or contact him at dan@lexiconsystemsinc.com.
THanks to the following technical expert for reviewing this article: Jesse Liberty
msdnmagazine.com
Instantly Search Terabytes of Data
across a desktop, network, Internet or Intranet site with dtSearch enterprise and developer products
Over 25 search features, with easy multicolor hit-highlighting options
dtSearch’s document filters support popular file types, emails with multilevel attachments, databases, web data
Developers:
• APIs for .NET, Java and C++
• SDKs for Windows, UWP, Linux, Mac and Android
• See dtSearch.com for articles on faceted search, advanced data classification, working with SQL, NoSQL & other DBs, MS Azure, etc.
Visit dtSearch.com for
• hundreds of reviews and case studies • fully-functional evaluations
The Smart Choice for Text Retrieval® since 1991
dtSearch.com 1-800-IT-FINDS
®





































































   27   28   29   30   31