Home > OS >  How to display months and days in Vietnamese in DatePickerDialog?
How to display months and days in Vietnamese in DatePickerDialog?

Time:10-20

How to display months and days in Vietnamese in DatePickerDialog for Android and DatePicker in IOS when the app language to Vietnamese in Xamarin forms

Android:

protected override DatePickerDialog CreateDatePickerDialog(int year, int month, int day)
        {
            pickerDialog = new DatePickerDialog(Context, (o, e) =>
            {
                datePicker.Date = e.Date;
                ((IElementController)datePicker).SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false);
            }, year, month, day);

            //ok
            pickerDialog.SetButton((int)DialogButtonType.Positive, AppResources.AlertDismiss, OnDone);

            //cancel
            pickerDialog.SetButton((int)DialogButtonType.Negative, AppResources.PickerCancelText, OnCancel);

            return pickerDialog;
        }

IOS: suggest me how to do in IOS?

CodePudding user response:

If I understand correctly , do you want to show English formatting for the DatePicker?

If so you can modify the Locale for the datepicker in custom renderer .

iOS Solution


[assembly: ExportRenderer(typeof(DatePicker), typeof(MyRenderer))]
namespace FormsApp.iOS
{
    class MyRenderer : DatePickerRenderer
    {

        protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e)
        {
            base.OnElementChanged(e);
          
            if(Control != null)
            {
                UIDatePicker picker = Control.InputView as UIDatePicker;
                picker.Locale = new NSLocale("us");
            }
        }
    }
}

Before

enter image description here

After

enter image description here


If you want the Datepicker only display month and day for selecting item , it could be a little complex , because iOS does not provide the option/mode to achieve that , you need to create a view and controller that implement the UIPickerViewDelegate and create your own .

Refer to

enter image description here

###After

enter image description here

Refer to

DatePickerDialog in arabic language

Set Android DatePicker title language

  • Related