开发者

are there any Validation Controls in WPF controls just like Validation Controls in ASP.net

开发者 https://www.devze.com 2023-03-11 16:53 出处:网络
I\'ve created a simple fo开发者_JS百科rm in WPF. I have worked on ASP.NET previously, so I\'m wondering if there are \'Validation Controls\' in WPF that are similar to ASP.NET, or if I need to manuall

I've created a simple fo开发者_JS百科rm in WPF. I have worked on ASP.NET previously, so I'm wondering if there are 'Validation Controls' in WPF that are similar to ASP.NET, or if I need to manually validate my fields.

Thanks.


sure, you can easily do this. What you want is IDataErrorInfo interface.
here is an example.


If you are using Binding, here's a good post on Stackoverflow

Quickly, you want something like that :

<TextBox Text="{Binding Age, ValidatesOnDataErrors=True}" />

And then with DataAnnotations you specify your rules. Then you use the

string IDataErrorInfo.this[string columnName]

function to validate. I use that all accross my application.

0

精彩评论

暂无评论...
验证码 换一张
取 消