我想在文本框中實現數據庫中名稱是否存在的驗證。我正在用c#使用wpf。我在保存新數據的同時在文本框中實施了驗證。我的問題是在編輯模式下:當我進入編輯模式並嘗試保存時,出現錯誤,名稱已經存在。數據驗證在編輯模式下不起作用
下面的代碼在保存模式下工作正常但是當涉及到數據綁定時的編輯模式錯誤消息顯示。
請建議我一個很好的方法來實現編輯模式下的驗證。
class MyParent
{
public MyCarClass CurrentCarEntity {get; set;}
private void txtName_TextChanged(object sender, RoutedEventArgs e)
{
CurrentCarEntity.Name = txtName.Text.Trim();
var getName = //Code for getting name from local db
if(CurrentCarEntity.Name != Null)
{
if(getName.Equals(CurrentCarEntity.Name))
{
MessageBox.Show("Name Already Exists");
}
}
}
}
你說你已經在你的文本框中實現了驗證,但是在你的問題中沒有看到它。 – learningcs