-2

I have six textboxes in my WPF app, and I want to check if every single one of them is filled (that means the textboxes contains at least one letter, number, etc. (datatype doesn't matter!))

When not, I want to pop up Messagebox to inform the user to check them once again (that's just for context, I know how to do this specific thing). How do I check that? Everywhere I've searched, they somehow did it but in Windows Forms, which is not what I need, obviously.

LordWorm
  • 9
  • 6
  • 2
    Could this post answer your question? https://stackoverflow.com/questions/19539492/implement-validation-for-wpf-textboxes – J.Salas Dec 27 '21 at 14:01

1 Answers1

1

You can either check whether they have inputs or check them for specific input types (ie. validation). For validation I would suggest you read the following question and answers.

Implement Validation for WPF TextBoxes

But if you want to check whether a textbox has input or not, you can either check with "(string.IsNullOrEmpty(textbox.Text))" or "(textBox1.TextLength == 0)" or if you don't want "space" you can check with "(string.IsNullOrWhiteSpace(textbox.Text)).

You can traverse your WPF xml in various ways but I'd recommend following answer

Find all controls in WPF Window by type

Onur Dilek
  • 59
  • 5
  • That second part looks very promising and like something that I wanted, thanks, just one another question, do I have to do this for every single textbox in the code or is there any way to do it in one codeblock? (with some loop or method or anything?) – LordWorm Dec 27 '21 at 14:16
  • 1
    Second link shows how you can get them all in an ienumerable or any type you want. And since you can then do a foreach loop you can check them all in a block of code – Onur Dilek Dec 27 '21 at 14:20
  • Yeah, sorry, somehow overlooked that. Thank you for your answer. – LordWorm Dec 27 '21 at 14:26