Xamarin One platform to rule them all? Erwin de Groot @ 040 coders
.NET frameworks WPF UI SL UI UWP UI iOS UI Android UI MacOS UI Libraries Libraries Libraries Libraries Libraries Libraries Mono Mono Touch Android .NET .NET Xamarin. … framework Silverlight Mac Xamarin. Xamarin. iOS Android .NET Core
.NET standard WPF UI SL UI UWP UI iOS UI Android UI MacOS UI Libraries .NET standard interface .NET .NET Xamarin. Xamarin. Xamarin. .NET Core framework Silverlight iOS Android Mac
Xamarin Forms Linux UWP iOS Android macOS Shared UI Xamarin Forms Mono & Xamarin. Xamarin. Xamarin. .NET Core GTK# iOS Android Mac
Xamarin
Xamarin history
Xamarin & alternatives C#, XAML C++, QML C#, UnityScript, Boo Javascript, HTML5, CSS3 Open source MIT license Open source (L)GPL Proprietary Open source Apache License - Still maturing - No native controls - Focus on games - Slow UI - No native controls - No native controls + Customizable native + Mature rich UI + Great for games/3D + Fast development controls development
Visual Studio Xamarin Solution
From WPF to Xamarin.Forms WPF Xamarin.Forms Control Templates Rendering classes WPF names: Xamarin.Forms names: UserControl ContentView StackPanel StackLayout ScrollViewer ScrollView DataContext BindingContext Extended Binding functionality Basic Binding functionality ComboBox Picker ToolTips, Menu, ContextMenu -
User Interface rendering UI (XAML) StackLayout Button Xamarin.Forms StackLayout StackLayout StackLayout StackLayout Renderer Renderer Renderer Renderer Button Button Button Button Renderer Renderer Renderer Renderer UWP Android iOS macOS Xamarin Bindings StackPanel LinearLayout UIStackView NSStackView Button Button UIButton NSButton
Custom renderers
Custom renderers
Xamarin.Forms.DependencyService
Xamarin.Forms.DependencyService
Xamarin.Forms.DependencyService
Xamarin.Forms.DependencyService
My development setup Mac mini - Visual Studio for Mac - iOS emulators Laptop - Visual Studio Community - Android emulators iPhone SE Android phone (borrowed) iPad Air 2
Encountered issue #1 Deploying app to a device or simulator yields: “Couldn't connect to logcat, GetProcessId returned: 0” No idea what causes this, but when you uninstall the app from the device/simulator and try again, it works.
Encountered issue #2 Dunno. Try again.
Encountered issue #3 Latest Xamarin doesn’t support old .net standard anymore. Increase the ‘minimum supported windows version’ in the UWP app.
Encountered issue #4 .NET and Java each have their own garbage collection. What happens when you process a bunch of large (native) bitmaps? .NET Java Call ‘Dispose()’ on the bitmap when not used anymore, or use the ‘using’ construct. Listen to the ‘ OnTrimMemory ’ event and invoke the .NET Garbage Collection yourself.
Encountered issue #5 Compiler keeps complaining that the iOS app requires a LaunchScreen, but the LaunchScreen is there! ‘iPad multitask’ is a new option starting from iOS 11 and also happens to be enabled default. Somehow this causes the strange ‘ LaunchScreen ’ error. Simply disable the option.
Encountered issue #6 Xamarin.Forms 3.3.0 and up: removing a custom control from the macOS page causes a NullReferenceException. Issue is known, but not solved yet. Revert back to Xamarin.Forms 3.2.0 SkiaSharp 1.60.3 and older: when a canvas has size 0x0, an OutOfMemoryException occurs Upgrade SkiaSharp to 1.68.0 SkiaSharp 1.68.0 requires Xamarin.Forms 3.3.0
In conclusion: did Xamarin help? Flexibility • Custom renderers • • DependencyService A single UI definition • • Once set-up, quickly add features too all platforms. • Xamarin.macOS hasn’t matured yet Open source so you can fix it yourself • • Xamarin & community are pretty fast picking up issues Visual differences between platforms sometimes look awkward • You really need those custom renderers •
Recommend
More recommend