Articles in this section

How to change the editor visibility based on another editor in .NET MAUI DataForm (SfDataForm)?

In the Syncfusion® .NET MAUI DataForm, you can dynamically control the visibility of an editor based on the value of another editor. This is achieved by using the IsVisible property of the DataFormViewItem.

Ensure all properties in the model class implement the INotifyPropertyChanged interface to raise property changes.
C#:

Bind the DataFormModel properties to the DataObject property of SfDataForm. Raise the property changed event for DataObject in the behavior class.

protected override void OnAttachedTo(ContentPage bindable)
{
   base.OnAttachedTo(bindable);
   dataForm = bindable.FindByName<SfDataForm>("dataForm");
   if (dataForm != null)
   {
       dataForm.DataObject = new DataFormModel();
       dataForm.GenerateDataFormItem += OnGenerateDataFormItem;
       (dataForm.DataObject as DataFormModel).PropertyChanged += OnDataObjectPropertyChanged;
       dataForm.ItemsSourceProvider = new ItemSourceProvider();
       dataForm.RegisterEditor("Country", DataFormEditorType.AutoComplete);
   }
} 

C#:

Initially, set the visibility of the ConfirmPassword field to false using the GenerateDataFormItem event handler.

private void OnGenerateDataFormItem(object sender, GenerateDataFormItemEventArgs e)
{
   if (e.DataFormItem != null)
   {
       if (e.DataFormItem.FieldName == "ConfirmPassword")
       {
           e.DataFormItem.IsVisible = false;
       }
   }
}

C#:

With the OnDataObjectPropertyChanged event handler, we can change the visibility of the ConfirmPassword field based on the Password field value.

private void OnDataObjectPropertyChanged(object sender, PropertyChangedEventArgs e)
{
   string propertyName = e.PropertyName;
   if (propertyName != null && propertyName == "Password" && dataForm.DataObject != null && dataForm.DataObject is DataFormModel)
   {
       var confirmPassword = dataForm.GetDataFormItem("ConfirmPassword");
       confirmPassword.IsVisible = true;
   }
}

Download the complete sample from GitHub.

Output:

EditorVisibility.gif

Conclusion:

I hope you enjoyed learning how to change the visibility of the editor based on another editor in the .NET MAUI DataForm (SfDataForm).

Refer to our .NET MAUI DataForm feature tour page for its other groundbreaking feature representations. You can also explore our .NET MAUI DataForm documentation to understand how to present and manipulate data.

For current customers, check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI DataForm and other .NET MAUI components.

Please let us know in the following comments section if you have any queries or require clarification. Contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

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