SilverLight中的Xmal文本框验证 [英] Xmal textbox Validation in SilverLight

查看:73
本文介绍了SilverLight中的Xmal文本框验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我一种检查输入文本框数据的方法仅为0-9。

我做的就是这样,没关系。

< textbox keydown = TextBox_KeyDownname =txtboxwidth =250height =20grid.row =4grid.column =2horizo​​ntalalignment =leftmargin =4>



Please show me a way to check input textbox data is 0-9 only.
I made like this and it is OK.
<textbox keydown="TextBox_KeyDown" name="txtbox" width="250" height="20" grid.row="4" grid.column="2" horizontalalignment="Left" margin="4">

private void TextBox_KeyDown(object sender, KeyEventArgs e)
        {
            bool isDigit = e.Key >= Key.D0 && e.Key <= Key.D9;

            if (isDigit) { }
            else
                e.Handled = true;



}



但是我想在xaml文件中使用DecimalDigit :: ='0' - '9',所以对我来说这有点困难。

在此先感谢...


}

But I want to use "DecimalDigit ::= '0'-'9'" in xaml file and so it is a little difficulty for me.
Thanks in advance...

推荐答案

你好chitswemyint,有很多方法可以做到这一点。

我现在脑子里有一个:

1.扩展TextBox类。

2.添加一个名为Validation的属性。

3.添加一个与Validation属性一起使用的DependencyProperty。

4.创建一个使用正则表达式验证文本框的方法。

5.在您的XAML中,您可以根据需要添加验证属性。



快乐编码。



问候。
Hi chitswemyint, there is many ways to do that.
I have one in my mind right now:
1. Extend the TextBox class.
2. Add a property called "Validation".
3. Add a DependencyProperty that works with Validation property.
4. Create a method that use Regex to validate your textbox.
5. in your XAML you can add the Validation property as you wish.

Happy coding.

Regards.


这篇关于SilverLight中的Xmal文本框验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆