We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Possibility to Translate Enum Values in DataForm

When using enums I have used a localized description functionality in combination with humanize to have readable values. 
For normal XML I simply use a converter which displays the correct value like this.
<Label Grid.Row="0" Text="{Binding PRSubType, Converter={StaticResource EnumToLocalizedResourceConverter}}" HorizontalTextAlignment="Start" />
PRSubType in this case is an enum.

Now when I use the SFDataform I would like to do this too, but haven't found any documentation to enable a specific converter for the datafield.
I'm using the Display Attribute for the Label already, but the value would be great :) 

17 Replies

AK Ajith Kumar Senthil Kumar Syncfusion Team November 11, 2019 12:09 PM UTC

Hi Michael, 
 
Thanks for contacting Syncfusion support. 
 
Based on the provided information, we have analyzed your requirement of “Binding the enum value to the Label text along with converter” can be achieved by customizing the LayoutManager and overriding the GenerateViewForLabel method to handle the label text. 
 
Please refer the following code example for the same, 
 
[C#] 
protected override View GenerateViewForLabel(DataFormItem dataFormItem) 
{ 
    if (dataFormItem.Name.Equals("EmpName")) 
    { 
        EnumToLocalizeConverted labelTemplateConverter = new EnumToLocalizeConverted(); 
        Label label = new Label(); 
        label.BindingContext = new DataFormViewModel(); 
        Binding binding = new Binding("Designation"); 
        binding.Converter = labelTemplateConverter; 
        label.SetBinding(Label.TextProperty, binding); 
        label.FontSize = 18; 
        return label; 
    } 
    else 
    { 
        return base.GenerateViewForLabel(dataFormItem); 
    } 
} 
 
We have prepared sample based on your requirement, please find the sample by the following link. 
 
In the sample, as per your requirement we have bind the enum value with the text property of the label. 
 
You can also refer our online user guide documentation regarding customizing of LayoutManager by the following link, 
 
 
We hope this helps. Please let us know, if need any further assistance. 
 
Regards,
Ajith 
 



MI Michael November 15, 2019 03:36 PM UTC

Hi,


unfortunately this does not solve my question, as it translates the Label which I don't need to be translated. 
I need the Actual Enum Value translated. preferably in the picker too like this
<Picker Grid.Row="0" x:Name="NotificationTypePicker" Title="{i18N:Translate Text=NotificationType}" ItemsSource="{Binding NotificationTypes}" SelectedItem="{Binding NotificationType}"
                         ItemDisplayBinding="{Binding . , Converter={StaticResource EnumToLocalizedResourceConverter}}"/>
 


AK Ajith Kumar Senthil Kumar Syncfusion Team November 18, 2019 12:04 PM UTC

Hi Michael, 
 
Thank you for using Syncfusion products. 
 
Based on the provided information, your requirement of “Provide binding for the ItemDisplayBinding in DataFormPicker Editor along with converter” in Xamarin.Forms can be achieved by customizing the existing DataFormPicker editor. 
 
Please refer the following code example for the same, 
 
[C#] 
public class CustomPickerEditor : DataFormPickerEditor 
{ 
    DataFormViewModel dataFormViewModel = new DataFormViewModel(); 
    public CustomPickerEditor(SfDataForm dataForm) : base(dataForm) 
    { 
    } 
 
    protected override void OnInitializeView(DataFormItem dataFormItem, DataFormPicker view) 
    { 
        base.OnInitializeView(dataFormItem, view); 
        EnumToLocalizeConverted labelTemplateConverter = new EnumToLocalizeConverted(); 
        Binding binding = new Binding("SaveTo"); 
        binding.Converter = labelTemplateConverter; 
        view.BindingContext = dataFormViewModel; 
        view.SetBinding(DataFormPicker.ItemsSourceProperty, "Location"); 
        view.SetBinding(DataFormPicker.TitleProperty, "SaveTo"); 
        view.ItemDisplayBinding = binding; 
    } 
} 
 
 
You can also refer our online user guide documentation regarding the same by the following link, 
 
 
We hope this helps. Please let us know, if need any further assistance. 
 
Regards,
Ajith. 
 



MI Michael November 19, 2019 10:43 AM UTC

I created the new CustomPicker, but I'm immediately greeted with an exception when calling the 
base.OnInitializeView(dataFormItem, view);

as in your example
It seems that when registering the CustomPicker the Item is not created as DataFormPickerItem, but only as regular Item, at least that how it is shown when the DataForm_AutoGeneratingDataFormItem is triggered.



11-19 10:05:42.658 I/MonoDroid( 6446): UNHANDLED EXCEPTION:
11-19 10:05:42.659 I/MonoDroid( 6446): System.NullReferenceException: Object reference not set to an instance of an object.
11-19 10:05:42.659 I/MonoDroid( 6446):   at Syncfusion.XForms.DataForm.Editors.DataFormPickerEditor.OnUpdateValue (Syncfusion.XForms.DataForm.DataFormItem dataFormItem, Syncfusion.XForms.DataForm.Editors.DataFormPicker view) [0x0001b] in :0 
11-19 10:05:42.659 I/MonoDroid( 6446):   at Syncfusion.XForms.DataForm.Editors.DataFormPickerEditor.OnInitializeView (Syncfusion.XForms.DataForm.DataFormItem dataFormItem, Syncfusion.XForms.DataForm.Editors.DataFormPicker view) [0x00016] in :0 
11-19 10:05:42.659 I/MonoDroid( 6446):   at BoxPlanner.Views.Pages.CustomPickerEditor.OnInitializeView (Syncfusion.XForms.DataForm.DataFormItem dataFormItem, Syncfusion.XForms.DataForm.Editors.DataFormPicker view) [0x00001] in C:\Users\Micha\source\repos\BoxPlannerMobile\BoxPlanner\BoxPlanner\Views\Pages\Behavior\CustomPickerEditor.cs:21 
11-19 10:05:42.659 I/MonoDroid( 6446):   at Syncfusion.XForms.DataForm.Editors.DataFormEditor`1[EditorView].InitializeView (Syncfusion.XForms.DataForm.DataFormItem dataFormItem, Xamarin.Forms.View view) [0x00050] in :0 
11-19 10:05:42.659 I/MonoDroid( 6446):   at Syncfusion.Android.DataForm.Editors.DataFormPickerEditor.OnInitializeView (Syncfusion.Android.DataForm.DataFormItem dataFormItem, Syncfusion.Android.DataForm.Editors.SfPicker view) [0x0006a] in :0 
11-19 10:05:42.659 I/MonoDroid( 6446):   at Syncfusion.Android.DataForm.Editors.DataFormEditor`1[EditorView].InitializeView (Syncfusion.Android.DataForm.DataFormItem dataFormItem, Android.Views.View view) [0x00000] in :0 
11-19 10:05:42.659 I/MonoDroid( 6446):   at Syncfusion.Android.DataForm.DataFormLayoutManager.GenerateViewForEditor (Syncfusion.Android.DataForm.Editors.DataFormEditorBase editor, Syncfusion.Android.DataForm.DataFormItem dataFormItem) [0x00012] in :0 
11-19 10:05:42.659 I/MonoDroid( 6446):   at Syncfusion.Android.DataForm.DataFormLayoutManager.CreateNativeDataFormItemView (System.Int32 rowIndex, System.Int32 columnIndex) [0x000cc] in :0 
11-19 10:05:42.659 I/MonoDroid( 6446):   at Syncfusion.XForms.Android.DataForm.DataFormDependencyService.CreateNativeDataFormItemView (System.Object nativeObject, System.Int32 rowIndex, System.Int32 columnIndex) [0x00000] in :0 
11-19 10:05:42.659 I/MonoDroid( 6446):   at Syncfusion.XForms.DataForm.DataFormLayoutManager.CreateDataFormItemView (System.Int32 rowIndex, System.Int32 columnIndex) [0x00012] in :0 
11-19 10:05:42.659 I/MonoDroid( 6446):   at Syncfusion.Android.DataForm.DataFormLayoutManager.CreateDataFormItemView (System.Int32 rowIndex, System.Int32 columnIndex) [0x00006] in :0 
11-19 10:05:42.659 I/MonoDroid( 6446):   at Syncfusion.Android.DataForm.DataFormLayoutManager.CreateItemView (System.Int32 rowIndex, System.Int32 columnIndex) [0x00052] in :0 
11-19 10:05:42.659 I/MonoDroid( 6446):   at Syncfusion.Android.DataForm.ScrollPanel.GenerateItems (System.Int32 columnCount, System.Int32& actualStartIndex, System.Int32 actualEndIndex) [0x000df] in :0 
11-19 10:05:42.659 I/MonoDroid( 6446):   at Syncfusion.Android.DataForm.ScrollPanel.OnMeasure (System.Int32 widthMeasureSpec, System.Int32 heightMeasureSpec) [0x001fb] in :0 


AK Ajith Kumar Senthil Kumar Syncfusion Team November 20, 2019 10:18 AM UTC

Hi Michael, 
Thank you for the update. 
Based on the provided information and stack trace, we suspect that you have missed to register the editor as Picker. When we register as Picker, we can get the DataFormPickerItem in both AutogeneratingItem event and in customEditor. 
Please refer our online user guide documentation regarding the same by the following link, 
 
 
We hope this helps. Please let us know, if need any further assistance. 
 
Regards,
Ajith.  



MI Michael replied to Ajith Kumar Senthil Kumar November 21, 2019 08:14 AM UTC

Hi Michael, 
Thank you for the update. 
Based on the provided information and stack trace, we suspect that you have missed to register the editor as Picker. When we register as Picker, we can get the DataFormPickerItem in both AutogeneratingItem event and in customEditor. 
Please refer our online user guide documentation regarding the same by the following link, 
 
 
We hope this helps. Please let us know, if need any further assistance. 
 
Regards,
Ajith.  


Hi,

I did register my Attribute as the new customPicker
dataForm.RegisterEditor("CustomPickerEditor", new CustomPickerEditor(dataForm));
dataForm.RegisterEditor(typeof("MeasurementType", "CustomPickerEditor");

and even tried to use the generic assignment.
dataForm.RegisterEditor(typeof(Models.DAO.PRMeasurementType), "CustomPickerEditor");




AK Ajith Kumar Senthil Kumar Syncfusion Team November 22, 2019 09:42 AM UTC

Hi Micheal, 
 
Thank you for using Syncfusion products. 
 
Based on the provided information, your requirement of “Customizing of the existing picker editor” in Xamarin.Forms can be achieved using the RegisterEditor method of SfDataForm. 
Please refer the following code example for the same, 
 
[C#] 
            dataForm.RegisterEditor("ItemName", "Picker"); 
            dataForm.RegisterEditor("Picker", new CustomPickerEditor(dataForm)); 
 
We have prepared sample based on your requirement, please find the sample by the following link. 
 
In the sample, as per your requirement we have customized the existing picker editor, you modify the sample based on your scenario. 
 
We hope this helps. Please let us know, if need any further assistance. 
 
Regards,
Ajith. 
 



MI Michael February 20, 2022 07:34 PM UTC

Hi,


we tried to rework that example as described before to work on an enum picker, but it does only crash. 


Can you check the attached exampleß


Attachment: DataForm_13921f6b.rar


SS SaiGanesh Sakthivel Syncfusion Team February 21, 2022 12:02 PM UTC

Hi Michael, 
 
#Regarding crash in sfdataform 
The reported scenario is the sample level issue. We have suggest you to set the editor name as picker inside the RegisterEditor method to overcome the reported scenario in the sample. Please refer to the following code snippet for your reference. 
 
Code snippet 
protected override void OnAttachedTo(ContentPage bindable) 
{ 
    base.OnAttachedTo(bindable); 
    dataForm = bindable.FindByName<SfDataForm>("dataForm"); 
    dataForm.SourceProvider = new SourceProviderExt(); 
    dataForm.RegisterEditor("ItemName", "Picker"); 
    dataForm.RegisterEditor("Picker", new CustomPickerEditor(dataForm)); 
    dataForm.RegisterEditor("Gender", "Picker"); 
    dataForm.RegisterEditor("GenderPicker", new GenderPickerEditor(dataForm)); 
} 
  
Please refer to the modified sample in the following locations,
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/DataForm-1640116269
 
  
Please let us know if you have any concerns. 
 
Regards,
SaiGanesh Sakthivel
 



MI Michael replied to SaiGanesh Sakthivel February 21, 2022 08:27 PM UTC

By only changing this("Picker") the OnInitializeView is never called




SS SaiGanesh Sakthivel Syncfusion Team February 22, 2022 06:38 AM UTC

Hi Michael,

#Regarding customize the multipe picker with help of customDataFormPicker Editor
you can customize the multiple picker editors inside the single CustomDataFormPicker class. Please refer to the following code snippet for your reference.
 
 
Code snippet 
public class GenderPickerEditor : DataFormPickerEditor 
    { 
        public GenderPickerEditor(SfDataForm dataForm) : base(dataForm) 
        { 
        } 
 
        protected override void OnInitializeView(DataFormItem dataFormItem, DataFormPicker view) 
        { 
            if (dataFormItem.Name == "ItemName") 
            { 
                //// To customize the ItemName editor 
                view.TextColor = Color.Red; 
            } 
 
            if (dataFormItem.Name == "Gender") 
            { 
                //// To customize the Gender editor 
                view.TextColor = Color.Yellow; 
            } 
            base.OnInitializeView(dataFormItem, view); 
        } 
    } 
 
 
Behavior Class 
dataForm = bindable.FindByName<SfDataForm>("dataForm"); 
dataForm.SourceProvider = new SourceProviderExt(); 
dataForm.RegisterEditor("Picker", new GenderPickerEditor(dataForm)); 
dataForm.RegisterEditor("ItemName", "Picker"); 
dataForm.RegisterEditor("Gender", "Picker"); 
 
 
Please refer to the tested sample in the following locations,
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/DataForm1595969456
 
 
Please let us know if you have any concerns.

Regards,
SaiGanesh Sakthivel
 



MI Michael replied to SaiGanesh Sakthivel February 22, 2022 06:33 PM UTC

Ok so you are saying that it is ONLY possible to have 1 custom Picker per Dataform not multiple. 

if that's the case then this is unfortunate but ok. 


Now back to the original problem. 

I still don't get the Value in the Picker translated. The converter is actually triggered, but the values presented are still the source items not the translated value.

Updated sample attached. 

you can see when debugging that the description is used 

 return attributes[0].Description;




Attachment: DataForm_c8056030.rar


SS SaiGanesh Sakthivel Syncfusion Team February 23, 2022 01:40 PM UTC

Hi Michael, 
 
#Regarding binding for the ItemDisplayBinding in DataFormPicker Editor along with converter is not working 
Currently, we are validating the reported scenario from our end. we will update you on the further details on February 25, 2022. We appreciate the patience until then. 
 
Regards,
SaiGanesh Sakthivel
 



SS SaiGanesh Sakthivel Syncfusion Team February 25, 2022 02:03 PM UTC

Hi Michael, 
 
#Regarding binding for the ItemDisplayBinding in DataFormPicker Editor along with converter is not working  
Currently, we are validating the reported scenario in our source level. we will update you on the further details on March 1, 2022. We appreciate the patience until then. 
 
Regards,
SaiGanesh Sakthivel
 



SS SaiGanesh Sakthivel Syncfusion Team March 1, 2022 02:34 PM UTC

Hi Michael, 
 
#Regarding DataFormPicker is not translated the value 
We have analysis the reported scenario in our source level. We regret to inform you that as per the implementation of SfDataForm, there is no support available to translate the itemsource value in the view. 
 
Regards,
SaiGanesh Sakthivel
 



MI Michael March 1, 2022 07:37 PM UTC

Thanks for your reply, 


since this is a basic necessity to be able to have a multi language use case, I would like to raise this as a feature request. 



SS SaiGanesh Sakthivel Syncfusion Team March 2, 2022 02:32 PM UTC

Hi Michael, 
 
We have analyzed your requirement of “Provide a localization support for DataFormPickerEditor in SfDataForm”, as of now dataform doesn’t have the support for the same. We have logged a feature request for the same. We will implement this feature in any of our upcoming release.  
 
 
If you have any more specification/suggestions to the feature request, you can add it as a comment in the portal and cast your vote to make it count. 
 
Regards, 
SaiGanesh Sakthivel 


Loader.
Live Chat Icon For mobile
Up arrow icon