validation fails wpf mvvm
learning wpf with mvvm (using EF as ORM).
In my view model i have the property:
//---------------ClientNew
public const string ClientNewConst = "ClientNew";
private TBL_CLIENT _clientNew = new TBL_CLIENT();
public TBL_CLIENT ClientNew
{
get
{
return _clientNew;
}
set
{
if (_clientNew == value)
{
return;
}
var oldVal开发者_StackOverflowue = _clientNew;
_clientNew = value;
// Update bindings, no broadcast
RaisePropertyChanged(ClientNewConst);
}
}
where TBL_CLIENT - is an entittyobject that mirrors TBL_CLIENT table in DB
now, in my VIEW i bind bunch of textboxes like this(example only for client's first name):
<TextBox Style="{StaticResource ResourceKey=entryFormTextBox}"
Text="{Binding ClientNew.CLIENT_FIRST_NAME,
ValidatesOnDataErrors=True,
NotifyOnValidationError=true,
ValidatesOnExceptions=True,
UpdateSourceTrigger=LostFocus}"
Grid.Column="1"
Grid.Row="1" />
I tried to use different triggers for updatesource.. still teh validation does not work.
oh, i do have implemented idataerrorinfo interface in my viewmodel (but it never hits it..)
#region IDataErrorInfo Members
string IDataErrorInfo.Error
{
get { throw new NotImplementedException(); }
}
string IDataErrorInfo.this[string columnName]
{
get
{
if (string.IsNullOrEmpty("ClientNew.CLIENT_FIRST_NAME"))
{
return "Client Name is required";
}
return null;
}
}
#endregion
so, question.. how can i implement the simple as possible validation using idataerrorinfo for my case, where i don't have the separate property defined in ModelView for each of the entity object, but the property takes the whole entity object?
thanks in advance, Alex
You might have a look at the BookLibrary sample application of the WPF Application Framework (WAF). It defines the validation rules directly at the entity. Please have a look at "BookLibrary.Domain / Book.cs".
精彩评论