Hi Dave,
Thank you for contacting Syncfusion support.
Regarding query: convert a DataFormTextItem into a DataFormPickerItem
By default, the ItemsSource for picker is auto-generated for enum types and in order to display the picker other than enum data type, you can either set the ItemSource of property type in SourceProvider of SfDataForm which is used to add custom ItemsSource of DataFormPickerItem or you can set ItemSource through AutoGeneratingDataFormItemevent in SfDataForm. In either way you need to register the editor using RegisterEditor as Picker/DropDown in order to make data form item as DataFormPickerItem/DataFormDropDownItem based on the xamarin forms platform used.
Since Picker editor will not be supported in Xamarin.Forms.UWP platform and you can register the data form editor as DropDown for list, but it will not be supported in Xamarin.Forms iOS platform. You can refer our online documentation to know more about DropDownEditor.
Code snippet:
|
dataForm.DataObject = new ContactInfo();
if (Device.RuntimePlatform != Device.UWP) dataForm.RegisterEditor("LastName", "Picker"); else dataForm.RegisterEditor("LastName", "DropDown");
private void DataForm_AutoGeneratingDataFormItem(object sender, AutoGeneratingDataFormItemEventArgs e) { if (e.DataFormItem != null && e.DataFormItem.Name == "LastName") { var list = new List<string>(); list.Add("Home"); list.Add("Food"); list.Add("Utilities"); list.Add("Education");
if (Device.RuntimePlatform != Device.UWP) (e.DataFormItem as DataFormPickerItem).ItemsSource = list; else (e.DataFormItem as DataFormDropDownItem).ItemsSource = list;
} }
|
Though we had an issue with generating picker items through AutoGeneratingDataFormItem event. We have already found and fixed this issue in our Volume 2 SP2 release 2018. You can refer our release notes as well.
Could you please check with the provided sample and if further issue is reproduced, kindly revert us back by modifying the sample with further details about your query along with the below detail,
# SfDataForm vesion used.
Code snippet for DataObject class:
|
public class ContactInfo { private string firstName; private string lastName; private string title;
[Display(Name = "First Name")] public string FirstName { get { return this.firstName; } set { this.firstName = value; } }
[Display(Name = "Last Name")] public string LastName { get { return this.lastName; } set { this.lastName = value; } }
public string Title { get { return title; } set { title = value; } } }
|
Regarding query: create a list at run-time and convert the DataFormItem into a picker and assign the list?
Yes it is possible to create a list at run time and convert the DataFormIten in to picker item in SfDataForm Xamarin.Forms. It can be achieved by using RefreshLayout method of SfDataForm which is used to refresh the data form item created. You need to pass the True in RefreshLayout method to regenerate all the items from the committed data object . Also you can refresh the particular data form item .Please refer the below link more details on RefreshLayout.
Currently we have issue related to this query in our side. We have logged issue report for the same and we will include this fix in our upcoming Volume 3 SP1 release which is expected to be available by end of month October 30,2018 else kindly let us know if you need patch in advance.
Regards,
Jayaleshwari N