Disable autofill on the Xamarin.Forms PCL XAML page

I have a PCL that stores my MVVM pages in XAML. In the XAML file, I have the following, but I would like to disable the autocomplete function on the keyboard. Does anyone know how I can do this in XAML?

<Entry Text="{Binding Code}" Placeholder="Code" /> 
+8
source share
4 answers

Forms support the KeyboardFlags.Suggestion enum, which I assume is intended to control this behavior, but it doesn't seem to be very well documented.

+1
source

Custom Keyboard instances can be created in XAML using the x:FactoryMethod attribute. What you want can be achieved with the following markup:

 <Entry Text="{Binding Code}" Placeholder="Code"> <Entry.Keyboard> <Keyboard x:FactoryMethod="Create"> <x:Arguments> <KeyboardFlags>None</KeyboardFlags> </x:Arguments> </Keyboard> </Entry.Keyboard> </Entry> 

KeyboardFlags.None removes all special keyboard functions from the field.

In XAML, you can specify several enumerations , separating them with a comma:

 <KeyboardFlags>CapitalizeSentence,Spellcheck</KeyboardFlags> 

If you do not need a custom Keyboard , you can use one of the predefined ones using the x:Static attribute:

 <Entry Placeholder="Phone" Keyboard="{x:Static Keyboard.Telephone}" /> 
+20
source

KeyboardFlags should do this, something like:

 MyEntry.Keyboard = Keyboard.Create(KeyboardFlags.CapitalizeSentence | KeyboardFlags.Spellcheck); 
+1
source

While I already had the answer, it seemed to me that I would talk a little more about the use in XAML.

Unlike code, you cannot create a new instance of the Keyboard class to be used, but there is a way. I hope you have already xaml-ified your App.cs (uninstall it and create App.xaml and App.xaml.cs), so you don’t need to check if the Resources property has been initialized.

The next step is to override the OnStart () method and add the appropriate entries for the different keyboards that you use. I usually use three keyboards: numeric, electronic and text. Another useful is the Url keyboard, but you can add it in the same way.

 protected override void OnStart() { base.OnStart(); this.Resources.Add("KeyboardEmail", Keyboard.Email); this.Resources.Add("KeyboardText", Keyboard.Text); this.Resources.Add("KeyboardNumeric", Keyboard.Numeric); } 

This little code will make the keyboard accessible as static resources. To use them in XAML, follow these steps:

 <Entry x:Name="emailEntry" Text="{Binding EMail}" Keyboard="{StaticResource KeyboardEmail}" /> 

And now, your entry now has an email.

+1
source

Source: https://habr.com/ru/post/978269/


All Articles