I need to catch a change event (TextChanged) in the SfDataForm.

I need to catch a change event in the SfDataForm for each item (text change, date change, time change, number change), something similar to this:

<Editor Text="{Binding Name, Mode=TwoWay}">
                <Editor.Behaviors>
                    <behaviors:EventToCommandBehavior EventName="TextChanged" Command="{Binding NameChangedCommand}"/>
                </Editor.Behaviors>
 </Editor>

or

 <dataform:SfDataForm x:Name="dataForm" DataObject="{Binding CurrentModel}" LayoutOptions="TextInputLayout"  AutoGenerateItems="True">
            <dataform:SfDataForm.Behaviors>
                <behaviors:EventToCommandBehavior EventName="TextChanged" Command="{Binding DataFormItemTextChangedCommand}"/>
                <behaviors:EventToCommandBehavior EventName="DataFormItemChanged" Command="{Binding DataFormItemChangedCommand}"/>
            </dataform:SfDataForm.Behaviors>
</dataform:SfDataForm>

I use the AutoGenerateItems="True" and NameChangedCommand is in the ViewModel.

I tried to catch setting the value in the class ModelInfo property Name. This does not work correctly because the change occurs when the system is loading data. I need to catch a change event when a user has changed data in a control field.

How can you catch the event that the user changes data in SfDataForm? Is there an example?

3 Replies 1 reply marked as answer

SS SaiGanesh Sakthivel Syncfusion Team September 10, 2020 01:55 PM UTC

Hi Yury,  
  
Thank you for contacting syncfusion support.  
  
We have checked the reported query from our end. We would like to inform you that you can achieve your requirement by implementing the INotifyPropertyChanged in data object model class and raise property changed notifier for all the properties. Please refer to the following code snippet for your reference.  
  
Code snippet  
public MainPage()  
 
    InitializeComponent();  
    dataForm.DataObject = new ModelClass();  
    var formModel = dataForm.DataObject as ModelClass;  
    formModel.PropertyChanged += FormModel_PropertyChanged;  
 
private void FormModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)  
 
    var dataObject = sender as ModelClass;  
            
    if(e.PropertyName == "MiddleName" 
    {  
        App.Current.MainPage.DisplayAlert("", dataObject.MiddleName.ToString(), "OK");  
    }  
    if (e.PropertyName == "Email" 
    {  
        App.Current.MainPage.DisplayAlert("", dataObject.Email.ToString(), "OK");  
    }  
}  
  
We have attached the tested sample in the following link for your reference.  
  
We hope this helps.  
  
Regards,  
SaiGanesh Sakthivel 

Marked as answer

YU Yury September 10, 2020 07:50 PM UTC

Thank you! This helped me. :)
It's enough for me to subscribe to the ViewModelClass
ContactsInfo.PropertyChanged + = ContactsInfo_PropertyChanged;

These simple things sometimes seem complicated.


SS SaiGanesh Sakthivel Syncfusion Team September 11, 2020 01:14 PM UTC

Hi Yury,   
   
Thank you for the update.   
   
We are glad to know that the provided solution is resolved the issue at your side. Please let us know if you need any further assistance on this or you can close the incident. As always we are happy to help you out. 
   
Regards,   
SaiGanesh Sakthivel  


Loader.
Up arrow icon