Search code examples
iosxamarin.formsxamarin.iosuppercase

How to auto upper-case text for Editor/Entry in Xamarin Forms in iOS 11.4


In iOS version 11.2, I used this code to set auto upper-case text. It run OK.

Xamarin.Forms:

public static readonly BindableProperty HasAutoUpperCaseTextProperty =
         BindableProperty.Create(
             nameof(HasAutoUpperCaseText),
             typeof(bool),
             typeof(EditorExtend),
             false);
 
     public bool HasAutoUpperCaseText
     {
         get { return (bool)GetValue(HasAutoUpperCaseTextProperty); }
         set { SetValue(HasAutoUpperCaseTextProperty, value); }
     }

In iOS Renderer:*

Control.AutocapitalizationType = UITextAutocapitalizationType.AllCharacters;

Problem:

After I upgraded OS version of iPAD to iOS 11.4, It run incorrectly.

Have you ever met this problem? How to fix it in iOS 11.4?

Update:

I found problem, Auto-Capitalization (Go to Setting -> General -> Keyboard) was disable. So the iPAD device need to enable item Auto-Capitalization to use upper-case characters. enter image description here


Solution

  • *In iOS Renderer:

    protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);
    
            if (Control != null)
            {
                var nativeTextField = (UITextField)Control;
    
                nativeTextField.EditingChanged += (object sender, EventArgs args) =>
                {
                    nativeTextField.Text = nativeTextField.Text.ToUpper();
                };
    
            }
        }