Xamarin Forms

Basic difference between Xamarin.Forms and Xamarin.Native. Source: Ferrissey 2020
Basic difference between Xamarin.Forms and Xamarin.Native. Source: Ferrissey 2020

In traditional app development process, developers had to write code for iOS, Android and Windows platform separately. They had to maintain the codebase of each platform for the maintenance and upgradation process. It was a heavy time and money consuming task. Xamarin solved this problem to a great extent by providing the facility of backend code sharing across the platforms. It allowed developers to create the business logic once and share it across the iOS, Android and Windows platform. Eventually, Xamarin.Forms was developed to allow the developers to share the code of user interface of app across the platforms and make the development process easier.

Xamarin.Forms is an open source cross-platform UI development framework. It allows developers to build Android, iOS and Windows application from a single shared codebase. It supports C# language. Visual Studio is the recommended IDE for Xamarin.Forms.

Discussion

  • How does Xamarin.Forms work?
    Architecture of Xamarin.Forms applications. Source: Microsoft Docs 2021k.
    Architecture of Xamarin.Forms applications. Source: Microsoft Docs 2021k.

    A Xamarin.Forms application is designed similarly as a traditional cross-platform application. Shared code is usually placed in a .NET Standard library and platform-specific applications consume the shared code.

    Xamarin.Forms applications have a single class named App that instantiates the application on each platform. The AppShell class defines the visual hierarchy of the application. Shell uses this visual hierarchy to produce the user interface of the app.

    At runtime, Xamarin.Forms uses platform renderers to convert the cross-platform UI elements into native controls on Android, iOS and Windows devices. It enables the developer to give the native look, feel and user experience to the application while using the feature of code-sharing across platforms.

  • What are the benefits of Xamarin.Forms?

    It allows developers to create native UI layout and designs across platforms using a single shared codebase which reduces the time and money deployed in the development process . It allows developers to share code, test and business logic of app across multiple platforms. It reduces the overhead of managing different codebases for app due to separate code for different platforms.

    It's been claimed that while Xamarin enables 70% code sharing, Xamarin.Forms allows up to 95% code sharing. It's best for apps where code sharing is more important than custom UI. One team reported that with Xamarin.Forms they had only 135 lines of platform-specific code out of 3744 lines (96% reuse). Earlier with Xamarin the team had achieved 80% code reuse.

    PGS Software implemented European airline Volotea's mobile app in Xamarin.Forms. With Forms, consistent branding and styling were achieved across iOS and Android. With Forms, 70% of custom renderers were removed.

  • What platforms are supported in Xamarin Forms?

    Xamarin.Forms is used for making mobile apps (iOS or Android) and Universal Windows Platform (UWP) apps. UWP enables creation of apps that can run on any device with Windows 10 or 11. Visual Studio is the recommended IDE for it. For iOS, Xamarin.Forms applications can be written for iOS 9 or higher versions. For Android, apps can be written for Android 4.4 (API 19) or higher but Android 5.0 (API 21) is recommended as minimum API for full compatibility with all the Android supported libraries. For Windows platform, Windows 10 Universal Windows Platform, build 10.0.16299.0 or greater for .NET Standard 2.0 support. However, build 10.0.18362.0 or greater is recommended.

    Apart from iOS, Android and Windows Xamarin.Forms supports platforms including Samsung Tizen, macOS 10.13 or higher, GTK# and WPF. Windows 8.1 / Windows Phone 8.1 WinRT and Windows Phone 8 Silverlight are deprecated platforms for Xamarin.Forms version 3.0 or newer.

    To Develop for iOS platform on Windows computer, there must be a Mac computer accessible on the network because Apple's build tools are required to build native iOS apps, which run on Mac only. So, Visual Studio should be connected to a network-accessible Mac.

  • What are some essential terms used in Xamarin.Forms?
    Different types of layouts in Xamarin.Forms. Source: Microsoft Docs 2021d
    Different types of layouts in Xamarin.Forms. Source: Microsoft Docs 2021d

    Below are some essential terms used in Xamarin.Forms-

    • Views: Views are the basic building blocks of the user interface. Labels, buttons, and sliders are different types of views. Different views serve different purposes such as setting values and editing text.
    • Layouts: Layouts are the visual structure of the user interface. Layouts are containers for views and other layouts. Layouts and views derive from the View class. Layouts are also views containing a collection of child views.
    • Effects: Effects are used to customize the controls accordingly without implementing custom Renderer classes. They should be used when a small styling change is required. While, Custom renderers are better option for creating a new control.
    • Gestures: Gesture recognizers are used to detect user interaction with views in a Xamarin.Forms application. The Xamarin.Forms GestureRecognizer class supports tap, pinch, pan, swipe, and drag and drop gestures on View instances of the app.
    • Triggers: Triggers are used to define the actions in XAML after a certain events or property changes. State triggers are a specialized group of triggers that define when a VisualState should be applied.
  • What are the key building blocks of Xamarin.Forms?

    The key building blocks of a Xamarin.Forms application are as follows:

    • Xamarin.Essentials: Essentials provides a single cross-platform API that can work with any Xamarin.Forms, Android, iOS, or UWP application accessible from shared code regardless of how the user interface is created.
    • eXtensible Application Markup Language (XAML): XAML is used for instantiating and initializing objects and organizing those objects in a hierarchical way. In XAML, developers can use all the Xamarin.Forms views, layouts, pages as well as custom classes to create the UI. It is very brief and readable than the equivalent code.
    • Behaviors: Behaviors allows to add functionality to the user interface controls without extending to any other class. The functionality is already implemented in the behavior class so developers only need to attach it to the controls. They are created by deriving from the Behavior or Behavior<T> class.
    • Data binding: It is used to keep the objects synchronized so that changes in one object's property are automatically reflected in other related object's property. It is an important part of the Model-View-ViewModel (MVVM) application architecture.
  • What are the code-sharing techniques in Xamarin Forms?
    Code-sharing architecture in Xamarin.Forms. Source: Microsoft Docs 2021h
    Code-sharing architecture in Xamarin.Forms. Source: Microsoft Docs 2021h

    The.NET Standard Libraries and Shared Projects are two main methods of code-sharing. Developers can use a large number of .NET APIs to share the code across multiple platforms. .NET Standard 1.0 - 1.6 provides larger sets of APIs, whereas .NET Standard 2.0 provides the best coverage of the .NET Base Class Libraries (including the .NET APIs available in Xamarin apps). . In the shared projects method, a project is shared containing all the code files and assets of the app. Separate application projects for iOS, Android and Windows are shared inside the shared project. The common code for all the platforms also resides in the shared project.

    Portable Class Libraries allow developers to choose the combination of platforms for their project. However, Portable Class Libraries are deprecated in the latest version of Visual Studio, and .NET Standard Libraries are recommended instead.

  • What are platform-specific features and how to create them?
    Shadow platform-specific displayed on iOS and Android plaforms. Source: Microsoft Docs 2021j
    Shadow platform-specific displayed on iOS and Android plaforms. Source: Microsoft Docs 2021j

    A platform may have features and functionalities that doesn't exist on other platforms. For instance, Android has a functionality of fast scrolling in a list view but iOS doesn't have the same. Xamarin.Forms platform-specifics allow developers to utilize such platform-specific functionality that is only available on a specific platform without creating custom renderers or effects. There are some built-in platform-specifics in Xamarin.Forms, developers can use them or create the platform-specifics by themselves. Below are the steps for creating a platform-specific -

    • Implement the specific functionality as an Effect.
    • Create a platform-specific class that will use the Effect.
    • Make an attached property in the platform-specific class to allow the platform-specific to be used through XAML.
    • Implement extension methods in the platform-specific class, to allow the platform-specific to be used through a fluent code API.
    • Set the effect implementation to be applied only when the platform-specific has been invoked on the same platform as the Effect.

    Using an Effect as a platform-specific makes the effect easily consumable through XAML and a fluent code API.

  • What are the shortcomings of Xamarin forms?

    Though Xamarin.Forms can create a native UI for different platforms but it is not the best choice for creating native UI of complicated apps or apps that use more native functionalities such as camera, bluetooth. Also, the file size of Xamarin.Forms app is comparatively greater than the native ones. It is not a good choice for building games.

  • As a beginner, how do I get started with Xamarin.Forms?

    Xamarin.Forms has a complete documentation and code samples. There are many resources to learn Xamarin.Forms provided by the Microsoft, including:

    A beginner should use Xamarin.Forms Shell for the mobile app development. Xamarin.Forms Shell provides a common navigation user experience, a URI-based navigation scheme, and an integrated search handler. Thus, it makes the app development process easier.

Milestones

2011

Engineers who had created Mono, launch a new company named Xamarin. Mono itself was an open source project started in 2001 to bring .NET applications to Linux.

2014

Xamarin.Forms is created, enabling a single user interface to be used for different platforms. Xamarin.Forms 1.0.6197 is released as a bug fix release.

Apr
2018

Xamarin.Forms 2.5.1 is released. Multiple issues such as BindingContext object not being passed through CommandParameter and app crash while navigating to a TabbedPage are solved.

May
2018

Xamarin.Forms 3.0.0 is released. Flex layout is released. It's optimized for UI to adapt to various screen sizes and dimensions. Support for right to left languages is released. Developers can now create and customize Styles using CSS. VisualStateManager can now be used to handle different states of controls.

May
2020

At the BUILD 2020 conference, Microsoft announces .NET Multi-platform App UI (MAUI). This is meant as an evolution of Xamarin.Forms. Xamarin.Forms 5.0 will be the last major release before .NET MAUI.

Nov
2020

Xamarin.Forms 4.5.0.725 (4.5.0 Service Release 6) is released. Xamarin.Forms now uses the latest AndroidX libraries from Google instead of Android Support libraries.

Jul
2021

Xamarin.Forms 5.0.0.2337 (5.0.0 Service Release 9) is released. The release includes several new controls and features including App Themes (Dark Mode), Brushes, CarouselView, RadioButton, Shapes and Paths, and SwipeView. Visual Studio 2017 is no longer supported.

References

  1. Agramonte, Charlin. 2018. "Custom renderers VS Effects in Xamarin Forms." Blog, XamGirl, August 17. Accessed 2022-03-18.
  2. AltexSoft. 2016. "The Good and The Bad of Xamarin Mobile Development." Blog, AltexSoft, January 28. Updated 2020-11-13. Accessed 2022-03-12.
  3. Amy. 2022. "What is Xamarin.Forms?" Blog, Eastpoint, March 08. Accessed 2022-03-10.
  4. Cogan, Adam. 2015. "Getting 96% Code Reuse with Xamarin Forms." Blog, January 14. Accessed 2022-03-29.
  5. Cynoteck. 2015. "An introduction to Xamarin." Technology Solutions Private Limited, on SlideShare, June 16. Accessed 2022-03-29.
  6. Ferrissey, Nigel. 2020. "When to Use Xamarin.Forms vs Xamarin Native?" Blog, Telerik, October 05. Accessed 2022-03-07.
  7. Microsoft Docs. 2020a. "Xamarin.Essentials." Documentation, Xamarin, Microsoft, December 04. Accessed 2022-03-08.
  8. Microsoft Docs. 2020b. "Xamarin.Forms gestures." Documentation, Xamarin, Microsoft, August 07. Accessed 2022-03-10.
  9. Microsoft Docs. 2020c. "Introduction to Behaviors." Documentation, Xamarin, Microsoft, August 27. Accessed 2022-03-07.
  10. Microsoft Docs. 2020d. "Xamarin.Forms 4.5.0.725 (4.5.0 Service Release 6) Release Notes." Documentation, Xamarin, Microsoft, November 11. Accessed 2022-03-08.
  11. Microsoft Docs. 2021a. "Xamarin.Forms supported platforms." Documentation, Xamarin, Microsoft, July 08. Accessed 2022-03-10.
  12. Microsoft Docs. 2021b. "Pair to Mac for Xamarin.iOS development." Documentation, Xamarin, Microsoft, July 08. Accessed 2022-03-07.
  13. Microsoft Docs. 2021d. "Xamarin.Forms Layouts." Documentation, Xamarin, Microsoft, July 08. Accessed 2022-03-09.
  14. Microsoft Docs. 2021f. "Xamarin.Forms XAML Basics." Documentation, Xamarin, Microsoft, December 16. Accessed 2022-03-10.
  15. Microsoft Docs. 2021g. "Xamarin.Forms Data Binding." Documentation, Xamarin, Microsoft, July 08. Accessed 2022-03-10.
  16. Microsoft Docs. 2021h. "Sharing code overview." Documentation, Xamarin, Microsoft, July 12. Accessed 2022-03-11.
  17. Microsoft Docs. 2021i. "Portable Class Libraries (PCL)" Documentation, Xamarin, Microsoft, July 12. Accessed 2022-03-11.
  18. Microsoft Docs. 2021j. "Platform-Specifics." Documentation, Xamarin, Microsoft, July 08. Accessed 2022-03-10.
  19. Microsoft Docs. 2021k. "What is Xamarin.Forms?" Documentation, Xamarin, Microsoft, July 08. Accessed 2022-03-10.
  20. Microsoft Docs. 2021l. "Xamarin.Forms Shell." Documentation, Xamarin, Microsoft, March 03. Accessed 2022-03-10.
  21. Microsoft Docs. 2021m. "Xamarin.Forms Triggers." Documentation, Xamarin, Microsoft, July 08. Accessed 2022-03-10.
  22. Microsoft Docs. 2021n. "Create Xamarin.Forms behaviors." Documentation, Xamarin, Microsoft, July 08. Accessed 2022-03-10.
  23. Microsoft Docs. 2021o. "Xamarin.Forms Views." Documentation, Xamarin, Microsoft, July 08. Accessed 2022-03-18.
  24. Microsoft Docs. 2021p. "Xamarin.Forms 2.5.1 Service Release 1." Documentation, Xamarin, Microsoft, November 11. Accessed 2022-03-18.
  25. Microsoft Docs. 2021q. "Xamarin.Forms 3.0.0 Release Notes." Documentation, Xamarin, Microsoft, November 11. Accessed 2022-03-18.
  26. Microsoft Docs. 2021r. "Android Platform Features." Documentation, Xamarin, Microsoft, July 08. Accessed 2022-03-28.
  27. Microsoft Docs. 2021s. "Xamarin.Forms Quickstart Deep Dive." Documentation, Xamarin, Microsoft, December 16. Accessed 2022-03-28.
  28. Microsoft Docs. 2021t. "What's a Universal Windows Platform (UWP) app?" Documentation, Xamarin, Microsoft, February 16. Accessed 2022-03-29.
  29. Microsoft Docs. 2022. "Xamarin.Forms 5.0.0.2337 (5.0.0 Service Release 9) Release Notes." Documentation, Xamarin, Microsoft, January 26. Accessed 2022-03-09.
  30. Mono Project. 2018. "History." Documentation, Mono Project, May 22. Accessed 2022-03-29.
  31. Ortinau, David. 2021. "The New .NET Multi-platform App UI." Blog, Xamarin, Microsoft, February 3. Accessed 2022-03-29.
  32. Peruzal. 2018. "Introduction to Xamarin Forms." Xamarin Forms Guide, Peruzal, September 28. Accessed 2022-03-12.
  33. Ritscher, Walt. 2016. "Arranging Views with Xamarin.Forms Layout." CODE Magazine, May/June. Updated 2021-06-22. Accessed 2022-03-12.
  34. Sakovich, Natallia. 2019. "Why Use Xamarin for Cross-Platform Development." Blog, SaM Solutions, February 12. Updated 2021-09-22. Accessed 2022-03-29.
  35. Singleton, Jayme. 2020. "Xamarin Customer Showcase: PGS Software + Volotea." Blog, Xamarin, Microsoft, May 1. Accessed 2022-03-29.
  36. Susai Raj, Delpin. 2019. "Xamarin.Forms - Working With Effects." C# Corner, December 18. Accessed 2022-03-12.
  37. XAM Consulting. 2021. "The Evolution of Xamarin.Forms." XAM Consulting, May 12. Accessed 2022-03-10.

Further Reading

  1. Microsoft Docs. 2021k. "What is Xamarin.Forms?" Documentation, Xamarin, Microsoft, July 08. Accessed 2022-03-10.
  2. Ferrissey, Nigel. 2020. "When to Use Xamarin.Forms vs Xamarin Native?" Telerik, October 05. Accessed 2022-03-07.
  3. Peruzal. 2018. "Introduction to Xamarin Forms." Xamarin Forms Guide, Peruzal, September 28. Accessed 2022-03-12.

Article Stats

Author-wise Stats for Article Edits

Author
No. of Edits
No. of Chats
DevCoins
7
9
1465
4
5
883
1725
Words
1
Likes
3244
Hits

Cite As

Devopedia. 2022. "Xamarin Forms." Version 11, March 29. Accessed 2022-09-22. https://devopedia.org/xamarin-forms
Contributed by
2 authors


Last updated on
2022-03-29 06:35:02
  • Xamarin
  • Xamarin.Forms App Lifecycle
  • Xamarin.Forms Data Binding
  • Cross-Platform App Development
  • .NET MAUI
  • Universal Windows Platform