Print Page | Close Window

Field Level Validation

Printed From: IdeaBlade
Category: Cocktail
Forum Name: Community Forum
Forum Discription: A professional application framework using Caliburn.Micro and DevForce
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=4259
Printed Date: 10-Jun-2026 at 5:09am


Topic: Field Level Validation
Posted By: -ook
Subject: Field Level Validation
Date Posted: 01-Aug-2013 at 5:39pm
Hello
 
I have implemented validation as per the TempHire reference application, and note that DataAnnotations may also be used on individual properties (I am using code first approach).
 
I am using DevExpress controls that apparantly do not support dataannotations but rather the IDataErrorInfo approach. I have added the IDataErrorInfo interface to my class and have placed the correct validation code in the 'string IDataErrorInfo.this[string columnName]' method. Yet still the control does not show an error. I suspect it is an MVVM thing or the fact I seem to be mixing two types of validation.
 
Anyone have any pointers?
 
Thanks
Mark



Replies:
Posted By: mgood
Date Posted: 01-Aug-2013 at 5:53pm
This sounds like a DevExpress issue. Implementing IDataErrorInfo is redundant. DevForce entities implement IDataErrorInfo out of the box. If the controls don't show an error, then it is an issue with the control or possibly the binding. I recommend you contact DevExpress support. 




Posted By: -ook
Date Posted: 01-Aug-2013 at 7:04pm
I have changed the control to a TextBox thus simplifying the issue by using standard out of the box controls. I would expect a red outline to be displayed. I should note that I am using WPF.
I have read: http://drc.ideablade.com/devforce-2012/bin/view/Documentation/cocktail-validation - http://drc.ideablade.com/devforce-2012/bin/view/Documentation/cocktail-validation
and http://drc.ideablade.com/devforce-2012/bin/view/Documentation/verification-ui - http://drc.ideablade.com/devforce-2012/bin/view/Documentation/verification-ui
(this one seems to hint at more code required for WPF to get this to work)
and the code sample at: http://drc.ideablade.com/devforce-2012/bin/view/Documentation/code-sample-validation-wpf - http://drc.ideablade.com/devforce-2012/bin/view/Documentation/code-sample-validation-wpf
My binding appears correct:
<TextBox Text="{Binding ReportedBy, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=true}"/>
In the model I have tried:
/// <summary>Gets or sets the person who reported the incident. </summary>
[DataMember]
[Required]
public string ReportedBy { get; set; }
and even added:
/// <summary>Gets or sets the person who reported the incident. </summary>
[DataMember]
[Required]
[IdeaBlade.Validation.RequiredValueVerifier(ErrorMessageResourceName = "ReportedBy")]
public string ReportedBy { get; set; }
If I attempt save the record it will display a validation error dialog listing the fields in question that are at fault, but still no difference to the TextBox
I have also added the custom style as recommended in the sample:
<Style TargetType="{x:Type TextBox}">
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<DockPanel>
<TextBlock Foreground="Red" FontSize="20">!</TextBlock>
<AdornedElementPlaceholder/>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self},
Path=(Validation.Errors)[0].ErrorContent}"
/>
</Trigger>
</Style.Triggers>
</Style>
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<DockPanel>
<TextBlock Foreground="Red" FontSize="20">!</TextBlock>
<AdornedElementPlaceholder/>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self},
Path=(Validation.Errors)[0].ErrorContent}"
/>
</Trigger>
</Style.Triggers>
</Style>


Posted By: mgood
Date Posted: 01-Aug-2013 at 10:39pm
Yes, WPF validation is not straight forward. Works much better in Silverlight. It's often easier to use exception based validation in WPF. You found the right resources in our documentation. Follow those instructions and give exception based validation a try by changing VerifierOptions.ErrorNotificationMode as described here:  http://drc.ideablade.com/devforce-2012/bin/view/Documentation/verification-ui#HVerificationwithaWPFUI - http://drc.ideablade.com/devforce-2012/bin/view/Documentation/verification-ui#HVerificationwithaWPFUI



Print Page | Close Window