We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to render DataForm using ReactiveUI in Xamarin Forms?

Platform: Xamarin.Forms |
Control: SfDataForm |
Published Date: March 28, 2019 |
Last Revised Date: July 9, 2020

ReactiveUI is built on a reactive programming foundation and is specifically implemented utilizing Reactive Extensions. This article explains how to render dataform in ReactiveUI framework in Xamarin Forms.

XAML

DataForm definition in xaml.

<Grid>
    <dataForm:SfDataForm x:Name="dataForm" Grid.Row="0"/>
</Grid>

C#

The ContactInfo class (ViewModel) should be inherited from ReactiveObject.

    public class ContactInfo : ReactiveObject
    {
        private AddressInfo addressInfo;
        public AddressInfo AddressInfo
        {
            get => addressInfo;
            set => this.RaiseAndSetIfChanged(ref addressInfo, value);
        }
        public ContactInfo()
        {
            AddressInfo = new AddressInfo();
        }
    }
 
    public class AddressInfo
    {
        public string Name { get; set; }
        public string Address{ get; set; }
        public string Email { get; set; }
        public string City { get; set; }
    }

C#

Derive the MainPage from IViewFor<T>, implement this interface on your Views to support Routing and Binding, and then set up the bindings for DataObject in the main page for the defined view model.

    public partial class MainPage : ContentPage, IViewFor<ContactInfo>
    {
        public MainPage()
        {
            InitializeComponent();
            ViewModel = new ContactInfo();
            this.Bind(ViewModel, x => x.AddressInfo, x => x.dataForm.DataObject);
        }
 
        public ContactInfo ViewModel { get; set; }
        object IViewFor.ViewModel
        {
            get { return ViewModel; }
            set { ViewModel = (ContactInfo)value; }
        }
    }

Output

gif

View sample in GitHub

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon