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 bind data object in Xamarin.Forms DataForm (SfDataForm) using Fresh MVVM framework

Platform: Xamarin.Forms |
Control: SfDataForm |
Published Date: March 19, 2020 |
Last Revised Date: March 19, 2020

The SfDataForm allows you to work with FreshMVVM framework. To achieve this, follow the below steps:

Step 1: Install the FreshMVVM NuGet package in your shared code project.

Step 2: Create your XAML page (view) with name ending with “Page”.

namespace DataFormXamarin
{
    public partial class DataFormPage : ContentPage
    {
        public DataFormPage()
        {
            InitializeComponent();
        }
    }
}

Step 3: Create a page model with the name ending with PageModel and inherit FreshBasePageModel. If your Page name is MainPage, then the PageModel name should be MainPageModel and the namespace of Page and PageModel should be the same. In this PageModel, you can keep the ViewModel related properties.

namespace DataFormXamarin
{
    public class DataFormPageModel : FreshBasePageModel
    {
       
    }
}

Step 4: To raise property changed notifier, use RaisePropertyChanged method of base class in your PageModel.

namespace DataFormXamarin
{
    public class DataFormPageModel : FreshBasePageModel
    {
        private ContactsInfo contactsInfo;
        public ContactsInfo ContactsInfo
        {
            get { return this.contactsInfo; }
            set
            {
                this.contactsInfo = value;
                this.RaisePropertyChanged("ContactsInfo");
            }
        }
    }
}

Step 5: Set MainPage using PageModel in your App.xaml.cs file.

public partial class App : Application
{
    public App()
    {
        InitializeComponent();
        var page = FreshPageModelResolver.ResolvePageModel<DataFormPageModel>();
        var basicNavContainer = new FreshNavigationContainer(page);
        MainPage = basicNavContainer;
    }
}

Step 6: Bind the data to the SfDataform DataObject without mentioning the binding context.

<dataForm:SfDataForm x:Name="dataForm" 
                                      DataObject="{Binding ContactsInfo}" 
                                      LayoutOptions="TextInputLayout" />

 

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