James Montemagno Principal Program Manager – Mobile Developer Tools, Microsoft motz@microsoft.com Montemagno.com @JamesMontemagno Weekly development podcast mergeconflict.fm Weekly development show xamarinshow.com
iOS C# UI Windows C# UIAndroid C# UI Shared C# logic Xamarin’s unique approach Shared C# codebase • 100% native API access • High performance
Build native UIs for iOS, Android, and Windows from a single, shared C# codebase. Meet Xamarin.Forms
Xamarin + Xamarin.Forms Traditional Xamarin approach With Xamarin.Forms: More code-sharing, all native iOS C# UI Windows C# UIAndroid C# UI Shared C# Logic Shared C# Logic Xamarin.Forms
What’s included ✓ 40+ Pages, layouts, and controls (Build from code behind or XAML) ✓ Two-way data binding ✓ Navigation ✓ Animation API ✓ Dependency Service ✓ Messaging Center Shared C# Logic Shared UI Code
Pages Stack Absolute Relative Grid ContentView ScrollView Frame Content MasterDetail Navigation Tabbed Carousel Layouts
ActivityIndicator BoxView Button DatePicker Editor Entry Image Label ListView Map OpenGLView Picker ProgressBar SearchBar Slider Stepper TableView TimePicker WebView EntryCell ImageCell SwitchCell TextCell ViewCell Controls
Xamarin & Xamarin.Forms ecosystem
Native UI from shared code <?xml version="1.0" encoding="UTF-8"?> <TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="MyApp.MainPage"> <TabbedPage.Children> <ContentPage Title="Profile" Icon="Profile.png"> <StackLayout Spacing="20" Padding="20" VerticalOptions="Center"> <Entry Placeholder="Username" Text="{Binding Username}"/> <Entry Placeholder="Password" Text="{Binding Password}" IsPassword="true"/> <Button Text="Login" TextColor="White" BackgroundColor="#77D065" Command="{Binding LoginCommand}"/> </StackLayout> </ContentPage> <ContentPage Title="Settings" Icon="Settings.png"> <!-- Settings --> </ContentPage> </TabbedPage.Children> </TabbedPage>
Messaging Center ▪ Master Page: ▪ Detail Page:
XAML Compilation XAMLCXAML Parsed and inflated Parsed & turned into IL
XAML Compilation Usage At assembly level: [XamlCompilation(XamlCompilationOptions.Compile)] [XamlCompilation(XamlCompilationOptions.Skip)] [assembly: XamlCompilation(XamlCompilationOptions.Compile)] At class level:
• Image Loading & Caching • Trimmed down just for Images Introducing GlideX.Forms http://jonathanpeppers.com/Blog/glidex-forms---fast-images-for-xamarin-forms-on-android
• Web Urls • Files on disk • Android resources (drawables) • Byte array ( Install NuGet & Init
ListView CachingStrategy ✓ Improves scrolling performance ✓ RetainElement is currently the default
ListView CachingStrategy
Data Templates
Data Templates ItemTemplate="{StaticResource WeatherTemplateSelector}"
• Extend Forms functionality • Platform-specific implementations • Customize an existing control or write your own Custom Renderers
• Custom page (subclass PageRenderer) • Circle Image (subclass ImageRenderer) • Calendar (subclass ViewRenderer) Custom Renderers - Examples
Effects ✓ Custom renderer “lite” ✓ Change properties on the native control ✓ Optional ✓ “stringly-typed” X No methods or events X No replacing the control
Effects
Shared C# Backend
iOS Large Titles Platform Specifics C# XAML
Built-in UI Tweaks Platform Specifics
Access Native Features Easily Dependency Service
It is really fast! Dependency Service https://xamarinhelp.com/ioc-container-performance/
Shared C# Backend User Interface User Interface User Interface Geolocation Geolocation Geolocation Compass Compass Compass Keystore Keystore Keystore
SharedPreferences Preferences.Get(“my_key”, 0); NSUserDefaults ApplicationData
Xamarin.Essentials Common API
ResourceDictionary Improvements
Xamarin.Forms Shared C# Logic Windows C#Android C#iOS C#
https://github.com/praeclarum/Ooui
soundbite.fm
Thank you. James Montemagno Principal Program Manager – Mobile Developer Tools, Microsoft motz@microsoft.com Montemagno.com @JamesMontemagno Weekly development podcast mergeconflict.fm Weekly development show xamarinshow.com

Optimizing and Extending Xamarin.Forms iOS, Android, and UWP Apps