Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable autocomplete in Xamarin.Forms PCL XAML Page

I have a PCL which stores my MVVM pages in XAML. I have the following in the XAML file, but I'd like to disable the autocomplete feature on the keyboard. Does anyone know how I can do this in the XAML?

<Entry Text="{Binding Code}" Placeholder="Code" />
like image 783
benpage Avatar asked Nov 17 '14 05:11

benpage


2 Answers

Custom Keyboard instances can be created in XAML using the x:FactoryMethod attribute. What you're wanting 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 features from the field.

Multiple enums can be specified in XAML by separating them with a comma:

<KeyboardFlags>CapitalizeSentence,Spellcheck</KeyboardFlags>

When you don't need a custom Keyboard, you can use one of the predefined ones by taking advantage of the x:Static attribute:

<Entry Placeholder="Phone" Keyboard="{x:Static Keyboard.Telephone}" />
like image 170
Taylor Buchanan Avatar answered Oct 22 '22 12:10

Taylor Buchanan


While there's already an answer, I thought I'd elaborate a bit further about usage in XAML.

Unlike in code-behind, you cannot create a new instance of the Keyboard class to be used, but there IS a way. Hopefully you're already xaml-ified your App.cs (remove it, and create App.xaml and App.xaml.cs), that way you don't have to check if the Resources property has been initialized yet.

The next step is to override the OnStart() method, and add the proper entries for the various keyboards you use. I usually use three keyboards: numeric, e-mail and text. Another useful one is the Url keyboard, but you can add it 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 keyboards available as static resources. To use them in XAML, just do the following:

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

And voilá, your entry now has an e-mail keyboard.

like image 2
fonix232 Avatar answered Oct 22 '22 11:10

fonix232