- Home
- Forum
- Xamarin.Forms
- Possibility to Translate Enum Values in DataForm
Possibility to Translate Enum Values in DataForm
|
[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);
}
} |
Ajith
|
[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;
}
} |
Ajith.
Ajith.
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,
|
[C#]
dataForm.RegisterEditor("ItemName", "Picker");
dataForm.RegisterEditor("Picker", new CustomPickerEditor(dataForm)); |
Ajith.
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
|
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));
} |
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/DataForm-1640116269
SaiGanesh Sakthivel
By only changing this("Picker") the OnInitializeView is never called
#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.
|
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);
}
} |
|
dataForm = bindable.FindByName<SfDataForm>("dataForm");
dataForm.SourceProvider = new SourceProviderExt();
dataForm.RegisterEditor("Picker", new GenderPickerEditor(dataForm));
dataForm.RegisterEditor("ItemName", "Picker");
dataForm.RegisterEditor("Gender", "Picker"); |
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/DataForm1595969456
Regards,
SaiGanesh Sakthivel
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
SaiGanesh Sakthivel
SaiGanesh Sakthivel
SaiGanesh Sakthivel
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.
- 17 Replies
- 3 Participants
-
MI Michael
- Nov 10, 2019 02:19 PM UTC
- Mar 2, 2022 02:32 PM UTC