- Home
- Forum
- Xamarin.Forms
- SFDataForm and binding
SFDataForm and binding
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();
}
}
}
SIGN IN To post a reply.
5 Replies
FP
Farjana Parveen Ayubb
Syncfusion Team
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
MA
Mario
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
Attachment: DataForm_4e1390ad.zip
FP
Farjana Parveen Ayubb
Syncfusion Team
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
MA
Mario
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:
DB
Dinesh Babu Yadav
Syncfusion Team
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
SIGN IN To post a reply.
- 5 Replies
- 3 Participants
-
MA Mario
- Aug 12, 2019 09:09 PM UTC
- Aug 15, 2019 12:16 PM UTC