xaml - 如何在 xamarin 表单中自动大写键盘/输入
问题描述
我有两个条目用户名和密码。用户名和密码始终为大写。我如何强制键盘或输入内容时输入的文本为大写?
<Frame StyleClass="lpframe" x:Name="usernameFrame" CornerRadius="5" BorderColor="Transparent" HasShadow="False">
<StackLayout>
<Label Text="USERNAME" StyleClass="lbl-login">
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<On Platform="Android" Value="OpenSans-Semibold.ttf#OpenSans-Semibold"/>
</OnPlatform>
</Label.FontFamily>
</Label>
<local:CustomEntry Placeholder="Username" PlaceholderColor="#879baa" Unfocused="entUser_Unfocused" StyleClass="form-control" ReturnType="Next" x:Name="entUser">
<local:CustomEntry.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<On Platform="Android" Value="OpenSans-Regular.ttf#OpenSans-Regular"/>
</OnPlatform>
</local:CustomEntry.FontFamily>
</local:CustomEntry>
</StackLayout>
</Frame>
<Frame StyleClass="lpframe" x:Name="passwordFrame" CornerRadius="5" BorderColor="Transparent" HasShadow="False">
<StackLayout>
<Label Text="PASSWORD" StyleClass="lbl-login">
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<On Platform="Android" Value="OpenSans-Semibold.ttf#OpenSans-Semibold"/>
</OnPlatform>
</Label.FontFamily>
</Label>
<local:CustomEntry Placeholder="Password" PlaceholderColor="#879baa" Unfocused="entPassword_Unfocused" IsPassword="True" StyleClass="form-control" ReturnType="Go" x:Name="entPassword">
<local:CustomEntry.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<On Platform="Android" Value="OpenSans-Regular.ttf#OpenSans-Regular"/>
</OnPlatform>
</local:CustomEntry.FontFamily>
</local:CustomEntry>
</StackLayout>
</Frame>
解决方案
现在您可以使用 Create 方法工厂来修改键盘行为,如下所示:
<Entry Placeholder="Enter text here">
<Entry.Keyboard>
<Keyboard x:FactoryMethod="Create">
<x:Arguments>
<KeyboardFlags>CapitalizeWord</KeyboardFlags>
</x:Arguments>
</Keyboard>
</Entry.Keyboard>
这是官方文档:自定义键盘
以下是所有支持的标志:
- 无 - 键盘不添加任何功能。
- CapitalizeSentence - 表示每个输入的句子的第一个单词的第一个字母将自动大写。
- 拼写检查 - 表示将对输入的文本执行拼写检查。
- 建议 - 表示将对输入的文本提供单词完成。
- CapitalizeWord – 表示每个单词的第一个字母将自动大写。
- CapitalizeCharacter – 表示每个字符都将自动大写。
- CapitalizeNone – 表示不会发生自动大写。
- 全部 - 表示将对输入的文本进行拼写检查、单词补全和句子大写。
推荐阅读
- excel - 为什么平方列会产生不同的答案
- python - subprocess.Popen 如何在 Windows 上与 shell=False 一起使用?
- node.js - SharedKeyCredential 不是构造函数 - Azure Blob Storage + Nodejs
- javascript - TinySlider:使上一个/下一个按钮在第一个/最后一个索引时消失?
- java - 如何使用 Spring 组件注册 POJO 工厂 *methods*?
- android - HUAWEI MediaPad M5 Lite 10 返回 screenLayout SCREENLAYOUT_SIZE_LARGE
- r - R:从数据框中的值中提取向量名称
- django - 如何在将商品添加到购物车时将用户重定向到登录页面?
- api - Flutter API 导致 Null
- ffmpeg - FFMPEG 流从 sdp 到 youtube/facebook live(RTMP)