windows phone中textbox只能输入数字
2012-11-24 18:27
225 查看
两种方法
第一种比较简单,直接设置textbox的属性,属性是InputScope
第二种就比较麻烦,需要添加一个类,使该类继承于textbox,然后设置其只能输入数字,需要在xaml页面添加命名空间,然后引用就行了
设置类的代码:
private readonly Key[] numeric = new Key[] { Key.Back, Key.NumPad0, Key.NumPad1, Key.NumPad2, Key.NumPad3, Key.NumPad4, Key.NumPad5, Key.NumPad6, Key.NumPad7, Key.NumPad8, Key.NumPad9 }; public NumericTextBox() { //将文本设置为 电话号码的文本输入模式 this.Width = 300.0; this.Height = 80.0; this.InputScope = new InputScope(); this.InputScope.Names.Add(new InputScopeName() { NameValue = InputScopeNameValue.TelephoneNumber }); } protected override void OnKeyDown(KeyEventArgs e) { //如果是数字键或者返回键则设置e.Handled = true; 表示事件已经处理 if(Array.IndexOf(numeric,e.Key) == -1) { e.Handled = true; } base.OnKeyDown(e); // important, if not called the back button is not handled }
相关文章推荐
- windows phone中textbox只能输入数字 .
- Winform TextBox中只能输入数字的几种常用方法(C#)
- ASP.NET 中Textbox只能输入数字,不能输入其他字符
- C#中TextBox只能输入数字的代码
- C#设置textBox只能输入数字(正数,负数,小数)简单实现
- C#Winform下用正则表达式限制TextBox只能输入数字
- C#中textbox只能输入数字
- C# TextBox控件只能输入数字
- 一个只能输入数字的TEXTBOX
- WPF中,一个只能输入Double类型数字的TextBox控件的类
- C#textbox只显示数字,只能输入数字
- 只能输入数字的TextBox
- TextBox只能输入数字[转]
- Win Form中限制TextBox只能输入数字
- C#的winform中控制TextBox中只能输入数字?
- C#中TextBox只能输入数字的代码
- 【转】一劳永获的解决textbox 只能输入数字、汉字、字母等问题
- asp.net TextBox只能输入数字和小数
- WPF C# VS2013 TextBox控件 限制只能输入数字
- C# TextBox中只能输入数字的几种常用方法(C#)