Practical .NET

Choosing a Xamarin Strategy

The dream of Xamarin is to allow you to create applications that run on tablets and smartphones (basically, Android/iOS smartphones and tablets plus Windows Surface laptops). By and large, it succeeds. However, if you're considering using Xamarin as your way to leap into mobile development, there are some key issues you should be aware of.

Supporting Multiple Platforms
The major one is that a Xamarin project doesn't, in fact, create output that runs on Android/iOS/Universal Windows Platform (UWP) platforms. Instead, when you create a Xamarin solution in Visual Studio, you can have up to four projects in your solution: Up to three projects, each targeted for iOS or Android or UWP development, and a Visual Studio Class Library (.NET Standard) holding any common code.

This leads to another key point: There are actually two different ways of creating a mobile application in Xamarin. You can choose to create your UI in each of the Android, iOS or UWP applications. Alternatively, you can create your UI using Xamarin.Forms in the shared class library. If you use Xamarin.Forms, the build process will generate a platform-specific UI for each of the iOS/Android/UWP projects.

Using Xamarin.Forms will decrease the amount of platform-specific code in your application compared to recreating your UI in each target platform. However, it won't eliminate it: You should assume that anywhere from 10 percent to 30 percent of your code will need to be specially written for each platform (though you'll still get to write all your code in Visual Studio, using C#). Of course, much will depend on which platform-specific features you decide to take advantage of.

Xamarin University (an excellent source for Xamarin training, by the way) suggests that there are three criteria to consider when deciding to use Xamarin Forms:

  • Is the application primarily oriented toward data entry? If it is, then Xamarin.Forms may be your best choice. You're not completely limited to data entry, though -- Xamarin.Forms includes some basic mapping functionality, for example.
  • Are you prototyping an application? Here again, Xamarin.Forms may be your best choice. After you get your application working, you can consider creating platform-specific UIs.
  • The last issue is key: You don't need a "pixel-perfect" UI design. Some of the control spacing and control colors for the platform-specific controls generated from your Xamarin.Forms design are outside your control. You have to be willing to give up some control of the UI on each platform if you're going to use Xamarin.Forms.

Supporting Development for Multiple Platforms
For Android development you need to install the Android SDK on to your Windows computer. If you're using Visual Studio 2017 (the Community Edition is free!), you can debug your application on an Android phone running Android 4.2 or later by using Xamarin's Live Player -- a process which turns out to be surprisingly easy. Without Visual Studio 2017 you must use one of the emulators that comes with the Android SDK, though. Be aware that if your computer doesn't have a graphics accelerator, the emulators can be very slow.

For debugging iPhones/iPad apps you can also use Visual Studio 2017 and Live Player, using an iPhone running iOS 6 or later. However, you'll also need a computer running the Macintosh OS to compile your app and create your deployable package. Xamarin provides some excellent tools to seamlessly fire your source code over to a Macintosh computer on your network when you start a build in Visual Studio.

If you've got all of this then you're ready to start setting up your Xamarin development environment. I'll discuss that in an upcoming column

About the Author

Peter Vogel is a system architect and principal in PH&V Information Services. PH&V provides full-stack consulting from UX design through object modeling to database design. Peter tweets about his VSM columns with the hashtag #vogelarticles. His blog posts on user experience design can be found at http://blog.learningtree.com/tag/ui/.

comments powered by Disqus

Featured

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

  • What's New for Python, Java in Visual Studio Code

    Microsoft announced March 2024 updates to its Python and Java extensions for Visual Studio Code, the open source-based, cross-platform code editor that has repeatedly been named the No. 1 tool in major development surveys.

Subscribe on YouTube