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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

SFDataForm and binding

Thread ID:

Created:

Updated:

Platform:

Replies:

146652 Aug 12,2019 09:09 PM UTC Aug 15,2019 12:16 PM UTC Xamarin.Forms 5
loading
Tags: SfDataForm
Mario
Asked On August 12, 2019 09:09 PM UTC

I have a SFDataForm declared in xaml and bound to an Item in my ViewModel. In the ViewModel when i set the value like Item.Number = "123456" (see SomeMethod) in the ViewModel, the SFDataForm doesn't update the value on the user interface. Can you please advise how I can update the field on the SFDataForm  to reflect the new value. 

 <dataForm:SfDataForm x:Name="dataFormHeader" DataObject="{Binding Item}"  />

ViewModel:

public class ViewModel : INotifyPropertyChanged {

          private ItemModel _item;
public ItemModel Item 
     get { return _item; }
     set {
          _item = value;
          OnPropertyChanged();
     }

}
public void SomeMethod() {
     this.Item.Number = "123456";
     //When we set the value of the number the value doesn't get updated on the SfDataForm.
}
}

public class ItemModel : INotifyPropertyChanged  
{
     private string _num;
     public string Number {
          get { return _num; }
          set {
               _num = value;
               OnPropertyChanged();
          }
     }

}



Farjana Parveen Ayubb [Syncfusion]
Replied On August 13, 2019 08:54 AM UTC

Hi Mario, 
 
Thank you for contacting Syncfusion support. 
 
We have checked the reported issue Field default value doesn’t reflect in the view and it’s working fine from our end. Based on the shared code we suspect that the Method SomeMethod doesn’t call from anywhere hence the value not updated to the property. Kindly ensure the same. 
 
Code Snippet [C#] : 
         
    public class DataFormViewModel 
    { 
        private DataFormModel _item; 
        public DataFormModel Item 
        { 
            get { return _item; } 
            set 
            { 
                _item = value; 
            } 
        } 
        public void SomeMethod() 
        { 
            this.Item.Number = "123456"; 
        } 
        public DataFormViewModel() 
        { 
            this._item = new DataFormModel(); 
            this.SomeMethod(); 
        } 
    } 
 
We have prepared a simple sample based on your requirement, 
 
Sample link: DataForm 
 
We hope this helps. Please let us know, if you would require any further assistance. 
 
Regards, 
Farjana Parveen A 


Mario
Replied On August 13, 2019 02:16 PM UTC

Yes it does work on initial initialization. I modified your sample to do what I'm trying to do. I added a button. Button changes the Number to "hello World". Notice its not updated on the SfDataForm.



Attachment: DataForm_4e1390ad.zip

Farjana Parveen Ayubb [Syncfusion]
Replied On August 14, 2019 06:13 AM UTC

Hi Mario, 
 
Thank you for the update. 
 
Based on the shared information we have checked your requirement of Changing DataFormItem value dynamically using Button. Since you are changing value in dynamic need to raise PropertyChanged event for DataObject ViewModel property and set NotifyPropertyChanges to True for DataForm. 
 
Code Snippet: 
[XAML] 
    <dataForm:SfDataForm Grid.Row="1" x:Name="dataForm" DataObject="{Binding Item}" NotifyPropertyChanges="True"/> 
 
[C#]         
    public DataFormModel Item 
    { 
            get { return _item; } 
            set 
            { 
                _item = value; 
                this.RaisePropertyChanged("Item"); 
            } 
     } 
 
 
We have modified the sample for the same, 
 
Sample link: DataForm 
 
We hope this helps. Kindly revert us if you have any concern. 
 
Regards, 
Farjana Parveen A 


Mario
Replied On August 14, 2019 01:38 PM UTC

Thanks so much that solved a lot of problems. Wish the property NotifyPropertyChanges="True" would of been documented below:


Dinesh Babu Yadav [Syncfusion]
Replied On August 15, 2019 12:16 PM UTC

Hi Mario, 
 
Thanks for the update. We have considered to improve DataForm UG document and it will be publish along with volume 3 release.   
 
Regards, 
Dinesh Babu Yadav 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

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

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