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" />
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}" />
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With