I am trying to implement a dynamic form using the SFDataForm control with the DataObject bound to a view model containing an entire set of about 80 properties. The idea is for a user to select a "Form" from a SFComboBox and have the DataForm regenerate and hide the items that don't exist on the selected form. Each "form" is simply an object with list of the property names (out of the 80 possible properties on the view model) to be displayed by the DataForm.
To accomplish this, I am trying to use the DataForm_AutoGeneratingDataFormItem event and cancel each item that isn't in the list of properties in the selected form. It appears that the DataForm_AutoGeneratingDataFormItem event only fires during the initial rendering of the control. Calling RefreshLayout doesn't seem to trigger the refresh. Where am I going wrong?
Here's the relevant code:
private void DataForm_AutoGeneratingDataFormItem(object sender, Syncfusion.XForms.DataForm.AutoGeneratingDataFormItemEventArgs e)
{
if (e.DataFormItem.Name != null)
{
Debug.WriteLine(e.DataFormItem.Name);
//Get a copy of the view model
if (_vm == null)
_vm = (TrackingViewModel)this.BindingContext;
//if the item being generated isn't in the list of fields for the selected report then don't create it
if (!_vm.SelectedForm.FormFields.Contains(e.DataFormItem.Name))
e.Cancel = true;
}
}
private void SfComboBox_SelectionChanged(object sender, Syncfusion.XForms.ComboBox.SelectionChangedEventArgs e)
{
//User selected a different Form to display
dataForm.RefreshLayout();
}