【发布时间】:2009-10-21 17:15:40
【问题描述】:
当用户点击按钮时如何强制验证?
人们会认为这应该很容易,因为如果元素值有效,您总是需要做一些事情。
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();
}
你可以猜到,根据我的验证器,空值是无效的(如果我在文本框中输入一些内容)然后清空它并模糊焦点它将显示无效值。
附带说明:UpdateSourceTrigger 不会影响初始值未验证的相关问题。
【问题讨论】: