DEV Community

Akash Kava for Web Atoms

Posted on • Updated on

How to use third party controls in Web Atoms for Xamarin.Forms?

As you have seen in previous article on how to use TypeScript with TSX (JSX) for Xamarin.Forms, it describes usage of default Xamarin.Forms controls.

However, using third party control is super easy, you can either use reflection to generate the class definitions or you can write them easily.

How it works?

bridge.getClass(assemblyQualifiedName: string) returns a .Net Type proxy which you can use to create object.


Just by looking at definition, you will understand how to create one...

Define a class

declare class FormField extends RootObject {

   // static field lets you define inline templates
   public static fieldTemplate: NodeFactory;

   public label: string;

   public required: boolean;

   public error: string;

   public errorColor: ColorItem;

   public errorBackgroundColor: ColorItem;


const ThirdParty = {
    FormField: bridge.getClass("Namespace.FormField, AssemblyName")
        as typeof FormField
Enter fullscreen mode Exit fullscreen mode

You may not need to create exact same hierarchy, as creating extra abstract classes do not serve any purpose unless they have some properties.

How to use?

Once all classes are defined, you can import and use them as shown below.

// this imports all default controls of Xamarin.Forms
import XF from "@web-atoms/xf-controls/dist/clr/XF";

import ThirdParty from "../clr/ThirdParty";

export default class MyFormPage extends AtomXFContentPage {

   public create() {

                 // This is typescript component

                 // this is how you can use your
                 // third party control
                     error={Bind.oneWay(() =>
                        text={Bind.twoWays(() =>


Enter fullscreen mode Exit fullscreen mode

The only reason we include all classes inside a default declaration is, while creating JSX, we can visually distinguish between CLR classes and TypeScript components. So all elements without . (Dot) are TypeScript components and all elements with . are CLR classes.

Defining Expandable Properties

This is little hacky, but simple one. Let's see how can we write MasterDetailPage in TSX.

           <XF.ContentPage ....
Enter fullscreen mode Exit fullscreen mode

Definition of MasterDetailPage is as follow,

class MasterDetailPage extends ContentPage {

   // this hacks is required to create expandable property
   public static header =;

   public header: any;

Enter fullscreen mode Exit fullscreen mode

Defining Attached Property

Control such as Grid has attached properties, which we can define and use as follow.

This is how grid is defined...

class Grid extends RootObject {

   // following are attached properties
   public static row = AttachedNode;

   public static column = AttachedNode;

   public static rowSpan = AttachedNode;

   public static columnSpan = AttachedNode;

   // following are expandable
   public static rowDefinitions = NodeFactory;

   public static columnDefinitions = NodeFactory;

Enter fullscreen mode Exit fullscreen mode


           <XF.RowDefinition height="Auto"/>
           // this is how attached property is used
           { ... XF.Grid.row(1) }
           { ... XF.Grid.columnSpan(2) }

Enter fullscreen mode Exit fullscreen mode

This way, you can define any third party components and you can use them inside TSX.

Top comments (0)