一个简单的UIValidate:

 

 

View:

<TextBlock Text="First Name:" Grid.Row="2" Style="{DynamicResource TBStyle}"></TextBlock>
<TextBox Grid.Row="2" Grid.Column="2" x:Name="firstNameTxt"
Text="{Binding Path=FirstName,ValidatesOnDataErrors=True,UpdateSourceTrigger=PropertyChanged}"
Validation.ErrorTemplate="{x:Null}"></TextBox>
<ContentPresenter Grid.Row="3" Grid.Column="2" Content="{Binding ElementName=firstNameTxt,Path=(Validation.Errors).CurrentItem}" />

<TextBlock Text="Last Name:" Grid.Row="4" Style="{DynamicResource TBStyle}"></TextBlock>
<TextBox Grid.Row="4" Grid.Column="2" x:Name="lastNameTxt"
Text="{Binding Path=LastName,ValidatesOnDataErrors=True,UpdateSourceTrigger=PropertyChanged}"
Validation.ErrorTemplate="{x:Null}"></TextBox>
<ContentPresenter Grid.Row="5" Grid.Column="2" Content="{Binding ElementName=lastNameTxt,Path=(Validation.Errors).CurrentItem}" />

ViewModel: 

实现接口IDataErrorInfo ,

string IDataErrorInfo.this[string propertyName]
{
get
{

// 这里返回相应的错误提示
string error = (_customer as IDataErrorInfo)[propertyName];

return error;
}
}