IDataErrorInfo implemented by entity class

Topics: Conventions, Getting Started, UI Architecture
Feb 21, 2012 at 10:06 PM
Edited Feb 22, 2012 at 5:42 PM

I have entity class:


public class Project
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
    public virtual string Description { get; set; }


this class implements IDataErrorInfo and INotifyPropertyChanged interfaces via Castle DynamicProxy interceptor. I have instance of this class in view model:


public class ProjectEditViewModel : Screen
    public Project Project { get; set; }



I am displaying this data in view:


<TextBox Grid.Row="0" Grid.Column="1" x:Name="Project_Name" Margin="4"/>
<TextBox Grid.Row="0" Grid.Column="2" x:Name="Project_Description" Margin="4"/>


INotifyPropertyChanged works well, but IDataErrorInfo not. It looks like IDataErrorInfo works only when it is implemented by viewmodel. Is there any simple way to have this validation on entity object instead of viewmodel?

Doing data validation by this aspect oriented programing makes the best sense to me so I would like to use it.

And if this is somehow connected with my problem, I am using this style to displaying validation errors:


<Style TargetType="{x:Type TextBox}">
     <Trigger Property="Validation.HasError" Value="true">
        <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors).CurrentItem.ErrorContent}"/>

My understanding of XAML is really poor so sorry if I missed something what is obvious.

I asked this question also at

Feb 22, 2012 at 9:17 PM
Edited Feb 22, 2012 at 9:18 PM

I found that the problem is in this convention:


ConventionManager.ApplyValidation = (binding, viewModelType, property) =>
    if (typeof(IDataErrorInfo).IsAssignableFrom(viewModelType))
        binding.ValidatesOnDataErrors = true;

IDataErrorInfo is not assignable from Project, because project not implements IDataErrorInfo directly but via Castle DynamicProxy. Is there a way how to check concrete instance and not just type?