UWP的TEXTBOX和PASSWORDBOX使用输入范围更改触摸键盘INPUTSCOPE

当你的应用运行在具有触摸屏的设备上时,触摸键盘可用于文本输入。当用户点击可编辑的输入字段(如 TextBox 或 PasswordBox)时,系统会调用触摸键盘。通过将文本控件的输入范围设置为与你期望用户输入的数据类型匹配,可以让用户在应用中更快捷地输入数据。输入范围会针对控件所预期的文本输入类型向系统提供提示,以便系统可以为该输入类型提供专用的触摸键盘布局。

1.限制TextBox的输入范围

例如:限制手机号码只能输入数字InputScope=”Number”,并且是11位数字MaxLength=”11”

<TextBox    x:Name="tbMobile"  InputScope="Number" MaxLength="11" PlaceholderText="手机号码" Margin="0,40,0,10" BorderThickness="0"  RelativePanel.AlignLeftWithPanel="True" RelativePanel.AlignRightWithPanel="True" />

手机号码的输入框如图:

 

2.由于PasswordBox比较特殊,不能直接使用InputScope进行设置,只能在后台进行代码设置;并且 PasswordBox 上的 InputScope 属性仅支持 Password 和 NumericPin 值。其他任何值将被忽略。

 

1 InputScope inputScope = new InputScope();
2 InputScopeName inputScopeName = new InputScopeName();
3 inputScopeName.NameValue = InputScopeNameValue.NumericPin;
4 inputScope.Names.Add(inputScopeName);
5 txtPwd.InputScope = inputScope;

 

PasswordBox输入框设置NumericPin 和TextBox设置InputScope=”Number”效果一致:

如果PasswordBox 上的 InputScope 设置 Password 则如图所示:

更多值请参考下列值:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WinUI 控件、UWP 控件、WPF 控件和 Silverlight 控件在语法和结构上有所不同,因此可以通过检查 XAML 代码的命名空间来区分它们。以下是一些常见的命名空间和控件: - WinUI 控件:命名空间为 `http://schemas.microsoft.com/winui/2021/xaml/behaviors` 或 `http://schemas.microsoft.com/winui/2021/xaml/presentation`,控件名称以 `Microsoft.UI` 开头。 - UWP 控件:命名空间为 `http://schemas.microsoft.com/winfx/2006/xaml/presentation` 或 `http://schemas.microsoft.com/winfx/2008/xaml/presentation`,控件名称以 `Windows.UI` 开头。 - WPF 控件:命名空间为 `http://schemas.microsoft.com/winfx/2006/xaml/presentation` 或 `http://schemas.microsoft.com/netfx/2007/xaml/presentation`,控件名称以 `System.Windows` 或 `Microsoft.Windows` 开头。 - Silverlight 控件:命名空间为 `http://schemas.microsoft.com/winfx/2006/xaml/presentation` 或 `http://schemas.microsoft.com/client/2007`,控件名称以 `System.Windows.Controls` 或 `Microsoft.Windows.Controls` 开头。 可以通过读取 XAML 文件中的命名空间来确定使用的控件类型。例如,以下代码片段演示了如何读取 XAML 文件中的命名空间: ```csharp using System.Xml.Linq; // Load XAML file into an XDocument XDocument xdoc = XDocument.Load("MyXamlFile.xaml"); // Get the root element of the XAML file XElement root = xdoc.Root; // Get the default namespace of the XAML file XNamespace ns = root.GetDefaultNamespace(); // Check the namespace to determine the type of controls used in the XAML file if (ns.NamespaceName.StartsWith("http://schemas.microsoft.com/winui")) { // WinUI controls } else if (ns.NamespaceName.StartsWith("http://schemas.microsoft.com/winfx")) { // UWP or WPF controls } else if (ns.NamespaceName.StartsWith("http://schemas.microsoft.com/client")) { // Silverlight controls } else { // Unknown namespace } ``` 请注意,这只是一种简单的方法来区分不同类型的控件,实际上还需要考虑一些其他因素,例如控件的属性和行为。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值