I know this is an old thread, but I found a way to do this in styles.
I have all of my styles defined in a ResourceDictionary
in my App.xaml
. There I can do things like:
<Style x:Key="StyleEntryNumeric" TargetType="Entry">
<Setter Property="ClearButtonVisibility" Value="WhileEditing" />
<Setter Property="Keyboard" Value="Numeric" />
</Style>
and then use it like:
<Entry Style="{DynamicResource StyleEntryNumeric}" />
But, what if I want to set KeyboardFlags
? Well, I did that with a bit of code in my App.xaml.cs
and a simple binding. First, in the top of my App.xaml
:
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="ThisControl"
x:Class="App.Forms.App">
Then where my styles are in the same App.xaml
:
<Style x:Key="StyleEntryText" TargetType="Entry">
<Setter Property="ClearButtonVisibility" Value="WhileEditing" />
<Setter Property="Keyboard" Value="{Binding Source={x:Reference ThisControl}, Path=KeyboardText}" />
</Style>
Finally, in my App.xaml.cs
code behind:
public Keyboard KeyboardText
=> Keyboard.Create(KeyboardFlags.CapitalizeNone | KeyboardFlags.Spellcheck);
And, I can create other similar properties in my code behind to use for other styles if needed.
None
member now. github.com/xamarin/Xamarin.Forms/blob/… – Musket