Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: Validation of multiple textboxes

Tags:

c#

validation

wpf

enter image description here

Here's the situation:

I've got 3 textboxes where one put First Name, Last Name and Age respectively. Label with big red "!" shall be only visible when:

Any of the textboxes has no content OR Age (third textbox) is a negative number OR Age is bigger than int.MaxValue.

I already got two validation rules (one for first/last name and another for age). What do I do now? Do I need some kind of converter that checks all three input fields and returns true/false? How to implement this in XAML?

like image 757
matt-pielat Avatar asked Jul 12 '26 08:07

matt-pielat


1 Answers

You can use IDataErrorInfo to validate the fields - see this article which explains how to use it. You'll just need to adapt it to have one field displaying errors instead of individual ones for all three.

like image 164
Gigi Avatar answered Jul 14 '26 21:07

Gigi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!