XAML中的文本框数据验证 [英] Text Box Data Validation in XAML

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

问题描述

大家好,

我需要在wpf应用程序中处理数据验证,其中必要的验证仅限于xaml文件.
即,
//a.xaml
.....
< window>
< grid>
< textbox height ="33" name ="MyLblelTxt" verticalalignment ="Top">
<标签名称="MyTextBox" Horizo​​nalAlignment =左"> DigitTB</标签</
< Button Horizo​​ntalAlignment ="Top" Name ="Button1"> Button</Button>


......
......
单击按钮时Textbox的一些基本属性,
1.只接受数字
2.应防止/禁止使用空字符
3.值的范围(即文本框应支持0-9999)
3.在文本框中键入非数字键(通过显示Redborder)时突出显示错误.
我需要知道如何仅在XAML中实现相同的目标,

我正在使用WPF VS2008,Windows 7 o/s.
解决上述问题的任何帮助都将是可观的.

问候,
Samanth_90

Hi All,

I need to handle data validation in my wpf application where the necessary validation confines to xaml file.
viz.,
//a.xaml
.....
<window>
<grid>
<textbox height="33" name="MyLblelTxt" verticalalignment="Top">
<Label Name="MyTextBox" HorizonalAlignment="Left">DigitTB</Label>
<Button HorizontalAlignment="Top" Name="Button1">Button</Button>


......
......
Some essential properties of Textbox on click of button,
1.Accept only numerals
2.Empty characters should be prevented/disallowed
3.Range of Values(viz., Text box should support 0-9999)
3.Highlight error on keying non-numerals(by display of Redborder) in the Text box.
I need to know how could one accomplish the same in XAML only,

I am using WPF VS2008, Windows 7 o/s.,
Any help in resolving the above would be appreciable.

With Regards,
Samanth_90

推荐答案

您无法完全在XAML中完成此操作.在某个时候,恐怕您需要编写一些代码.我写了一篇博客文章,以演示如何防止用户输入无效数字,因此,实际上不是在之后验证数据,而是从一开始就防止他们这样做.

您可以在此处找到此代码 [
There''s no way that you can complete this entirely in XAML. At some point, you need to write some code I''m afraid. I wrote a blog entry to demonstrate how you can prevent the user from entering invalid numbers, so rather than validating the data afterwards, you actually prevent them from doing this in the first place.

You can find this code here[^].


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

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