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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Possibility to Translate Enum Values in DataForm

Thread ID:

Created:

Updated:

Platform:

Replies:

148980 Nov 10,2019 02:19 PM UTC Nov 22,2019 09:42 AM UTC Xamarin.Forms 7
loading
Tags: SfDataForm
Michael
Asked On November 10, 2019 02:19 PM UTC

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 :) 

Ajith Kumar Senthil Kumar [Syncfusion]
Replied On 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 
 


Michael
Replied On 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}}"/>
 

Ajith Kumar Senthil Kumar [Syncfusion]
Replied On 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. 
 


Michael
Replied On 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 

Ajith Kumar Senthil Kumar [Syncfusion]
Replied On 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.  


Michael
Replied On 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");



Ajith Kumar Senthil Kumar [Syncfusion]
Replied On 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. 
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon