Articles in this section
Category / Section

How to save or cancel the edited DataForm data in Xamarin.Forms (SfDataForm) ?

5 mins read

You can save or cancel the DataObject in Xamarin.Forms SfDataForm by storing the dataobject.

C#

Raise the property change event to store the DataObject.

private void DataForm_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
    if(e.PropertyName == "DataObject")
    formModel = dataForm.DataObject as DataFormModel;
}

C#

Cancel will reset the DataObject with stored dataobject.

private void OnCancel(object sender, EventArgs e)
{
    dataForm.DataObject = formModel;
    foreach (var property in dataForm.DataObject.GetType().GetProperties())
    {
        dataForm.UpdateEditor(property.Name);
    }
}

C#

Saves the edited data by using Commit method.

private void OnSaved(object sender, EventArgs e)
{
    dataForm.Validate();
    dataForm.Commit();
    formModel = dataForm.DataObject as DataFormModel;
}

View sample in GitHub

 

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