Check WPF elements in C #?
How can I force validation when the user clicks a button?
One would think that this should be easy, as there is always something to do if the element values โโare valid.
private void buttonOk_Click(object sender, RoutedEventArgs e)
{
// How can I force the validation here? So that empty values are not allowed (validator doesn't allow those)
if (Validation.GetHasError(textBoxURI) ||
Validation.GetHasError(textBoxName)) // These return valid values if user has not changed values in fields.
return;
DialogResult = true;
this.Close();
}
As you can guess the empty value is not valid according to my validator (if I type something into the textbox) then clear it and blur focus it will show an invalid value.
As a side note: UpdateSourceTrigger
Will not affect the related issue of not validating initial values.
+2
source to share
2 answers