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
Most   Popular
Upcoming Events

.NET Insight

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.