xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

Entry keyboard changed to default when setting entry text from behavior. #5561

Open pieterlr opened 5 years ago

pieterlr commented 5 years ago

Description

I have a behavior on an Entry control. The behavior was to add a mask to the text while you enter it (from https://xamarinhelp.com/masked-entry-in-xamarin-forms/).

I noticed that whenever the behavior applied the mask, the keyboard was set back to the default one. IE if I set focus to the entry, then change the keyboard to the number keyboard and type numerical characters, the keyboard would switch back to the alphabet keyboard as soon as the mask was added.

I narrowed it down to these two lines that appear to be causing this: var entry = sender as Entry; entry.Text = "foo";

(in OnEntryTextChanged in the behavior).

Steps to Reproduce

  1. Click the entry box.
  2. Switch the keyboard to numerical keyboard.
  3. Type "1" (or anything) so that the OnEntryTextChanged will fire in the behavior.

Expected Behavior

"foo" displays in the entry and the keyboard is still the numeric keyboard.

Actual Behavior

"foo" displays in the entry, BUT the keyboard is now back to the default one.

Basic Information

This seems to be only on Android.

Screenshots

Default keyboard when you tap into the entry (step 1): image

Numeric keyboard (Step 2): image

Keyboard defaulted after step 3: image

This is the test app I've used: App4.zip

wangyankun33 commented 5 years ago

I also encountered this problem, have you solved it? I want to record the last keyboard type. When I next input, I switch directly to the last keyboard type. The data I found is basically setting the keyboard type. There is no way to get the keyboard type.