可以通过保存自定义键盘为静态,然后将其绑定到使用默认样式的所有输入字段做到这一点。您可以将该默认样式放入应用程序范围的资源字典中,该字典会自动应用于整个应用程序。下面是我刚刚测试了一个新的空表格项目来验证示例代码:
步骤1.保存自定义键盘为静态。
Keyboards.cs(静态自定义键盘):
using Xamarin.Forms;
namespace KeyboardDemo
{
public static class Keyboards
{
public static Keyboard Unassisted { get; private set; }
static Keyboards()
{
Unassisted = Keyboard.Create (0);
}
}
}
第2步:为您的项目创建一个App.xaml中。
关注这个头进行的App.xaml添加到您的表格项目:http://jfarrell.net/2015/02/02/centralize-your-styles-with-xamarin-forms/
第3步:添加默认样式的App.xaml
应用。XAML:
<?xml version="1.0" encoding="UTF-8"?>
<Application
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:demo="clr-namespace:KeyboardDemo"
x:Class="KeyboardDemo.App">
<Application.Resources>
<ResourceDictionary>
<Style x:Key="EntryStyle" TargetType="Entry">
<Setter Property="Keyboard" Value="{x:Static demo:Keyboards.Unassisted}" />
</Style>
<Style BasedOn="{StaticResource EntryStyle}" TargetType="Entry" />
</ResourceDictionary>
</Application.Resources>
</Application>
第4步:添加一个新的页面到项目
一个ContentPage添加到应用程序,与普通的输入控件来验证的造型。
App.xaml.cs:
using Xamarin.Forms;
namespace KeyboardDemo
{
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new MyPage();
}
}
}
MyPage.xaml:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="KeyboardDemo.MyPage">
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness" iOS="0,20,0,0" Android="0" WinPhone="0" />
</ContentPage.Padding>
<StackLayout>
<Entry />
</StackLayout>
</ContentPage>
的'Keyboard'属性是可绑定的,所以它的确可以通过样式来分配。 –
@KiethRome对,但是这迫使你选择Xamarin提供的预选键盘。您不仅可以使用样式禁用自动大写。因此,您可以选择文本或数字,或者除此之外还会更改其他键盘属性,而不仅仅是自动大写。 *编辑:看到你现在回答!我把它全部拿回来;) – hvaughan3