Home > Back-end >  How to check if every Textbox in WPF app is filled? (C#)
How to check if every Textbox in WPF app is filled? (C#)

Time:12-28

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.

CodePudding user response:

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

  • Related