News

Move Over XAML, Xamarin.Forms Now Does Markup in C#

Although C# markup for Xamarin.Forms has been available since Xamarin.Forms 4.6 (it's now at v4.7) debuted this spring, it was just "introduced" on the Microsoft Developer Blogs site by creator Vincent Hoogendoorn.

Traditionally, Xamarin.Forms markup (used to process, define and present text and UI features) was handled by the declarative language XAML (Extensible Application Markup Language) while logic coding for an app was done in C#. However, Hoogendoorn spearheaded an effort to use declarative style C# instead of XAML for Xamarin.Forms UI, as detailed in his CSharpForMarkup GitHub project. That single-language approach is exhibited in modern UI frameworks like Google's Flutter that uses the Dart programming language and SwiftUI, which uses Swift for iOS apps as a successor to Objective-C.

Hoogendoorn's GitHub site compares three different approaches for marking up an Entry box (more fully detailed here):

Entry Markup Comparison
[Click on image for larger view.] Entry Markup Comparison (source: GitHub).

Hoogendoorn's project resulted in C# Markup, which he describes "as a set of fluent helpers and classes that aim to make UI development in C# a joy."

He goes on: "C# Markup helps developers write concise declarative UI markup and cleanly separate it from UI logic, all in C#. Developers get to enjoy C#'s first-class IDE support when writing markup. A single language for markup and logic reduces friction, markup scattering and cognitive load; there is less or no need for language bridging mechanisms like separate converters, styles, resource dictionaries, behaviours, triggers and markup extensions."

C# Markup helpers provide a fluent API with Bind, Effects, Invoke, Assign, Row, Col, FormattedText, Style, Font, inline converters, support for using enums for Grid rows plus columns and more, Hoogendoorn's project says. Examples are shown here:

Some C# Markup Helper Examples
[Click on image for larger view.] Some C# Markup Helper Examples (source: Xamarin.Forms GitHub site).

The July 15 post details a Twitter search app created with the C# Markup approach, for which the source code can be found here.

"C# Markup makes Xamarin.Forms a more attractive alternative for developers who like the single language, declarative approach of modern UI frameworks like Flutter or SwiftUI," Hoogendoorn said in closing. "For new Xamarin.Forms developers without XAML knowledge, C# Markup shortens the learning curve.

"Last but not least, C# Markup does not force you to choose. Apps with a XAML UI can mix-in C# Markup just fine, e.g. to implement parts of the UI that are too complex / dynamic for XAML."

A full review and more guidance can be found in documentation, and feedback can be submitted via the C# Markup Pull Request.

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus

Featured

  • Full Stack Hands-On Development with .NET

    In the fast-paced realm of modern software development, proficiency across a full stack of technologies is not just beneficial, it's essential. Microsoft has an entire stack of open source development components in its .NET platform (formerly known as .NET Core) that can be used to build an end-to-end set of applications.

  • .NET-Centric Uno Platform Debuts 'Single Project' for 9 Targets

    "We've reduced the complexity of project files and eliminated the need for explicit NuGet package references, separate project libraries, or 'shared' projects."

  • Creating Reactive Applications in .NET

    In modern applications, data is being retrieved in asynchronous, real-time streams, as traditional pull requests where the clients asks for data from the server are becoming a thing of the past.

  • 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.

Subscribe on YouTube