Articles in this section
Category / Section

How to render DataForm using MVVMCross in Xamarin.Forms?

4 mins read

MvvmCross is a cross-platform MVVM framework that enables developers to create powerful cross-platform apps. This article explains how to render data form in MVVMCross framework in Xamarin.Forms.

The setup class is responsible for bootstrapping MvvmCross and registering platform services.

    public class Setup : MvxFormsAndroidSetup
        public Setup(Context applicationContext) : base(applicationContext)
        protected override MvxFormsApplication CreateFormsApplication()
            return new App();
        protected override IMvxApplication CreateApp()
            return new Core.CoreApp();
        protected override IMvxTrace CreateDebugTrace()
            return new DebugTrace();


An MvvmCross core project is supposed to include custom AppStart object that manages first navigation.

  public class CoreApp : MvvmCross.Core.ViewModels.MvxApplication
        public override void Initialize()


In this following code snippet, the first line does a bulk registration to the IoC container. It looks within the current Assembly (the “Core” Assembly) and uses reflection to register all the classes ending in service as lazily-constructed singletons.

ViewModels are key objects of the MVVM pattern. These should typically contain code for managing states and operations. When using MvvmCross, all your ViewModels should be inherited from MvxViewModel.

    public class MvxFormsViewModel : MvxViewModel
        public MvxFormsViewModel()
            this.contactsInfo = new ContactsInfo();
        private ContactsInfo contactsInfo;
        public ContactsInfo ContactsInfo
            get { return this.contactsInfo; }
            set { this.contactsInfo = value; }
        public override Task Initialize()
            //TODO: Add starting logic here
            return base.Initialize();
    public class ContactsInfo
        [Display(Name="First Name")]
        public string FirstName { get; set; }
        [Display(Name = "Middle Name")]
        public string MiddleName { get; set; }
        [Display(Name = "Last Name")]
        public string LastName { get; set; }
        [Display(Name = "Contact Number")]
        public string ContactNumber { get; set; }
        public int Age { get; set; }
        public string Email { get; set; }
        public string Address { get; set; }
        [Display(Name = "Birth Date")]
        public DateTime? BirthDate { get; set; }


Behavior lets you add functionality to data form. Xamarin.Forms behaviors are created by deriving from the Behavior or Behavior<T> class. 


    public class DataFormBehavior : Behavior<ContentPage>
        protected override void OnAttachedTo(ContentPage bindable)
            var dataForm = bindable.FindByName<SfDataForm>("dataForm");
            dataForm.AutoGeneratingDataFormItem += DataForm_AutoGeneratingDataFormItem;
        private void DataForm_AutoGeneratingDataFormItem(object sender, Syncfusion.XForms.DataForm.AutoGeneratingDataFormItemEventArgs e)
            if (e.DataFormItem != null && e.DataFormItem.Name == "Age")
                e.DataFormItem.IsVisible = false;



To use native MvvmCross bindings within a Xamarin.Forms page, simply add a reference to MvvmCross.Forms.Bindings (e.g.: xmlns:mvx="clr-namespace:MvvmCross.Forms.Bindings;assembly=MvvmCross.Forms") in the XAML page. Then, you can bind DataObject to the data form control using mvx:Bi.nd=""


<d:MvxContentPage x:TypeArguments="viewModels:MvxFormsViewModel"
               <dataForm:SfDataForm x:Name="dataForm" mvx:Bi.nd="DataObject ContactsInfo"/>  


    public partial class MvxFormsPage : MvxContentPage<MvxFormsViewModel>
        public MvxFormsPage()


Sample Demo: DataFormMVVMCross


Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment