DEVEX WPF CONTROLS VALIDATION

Posts   
 
    
AbbasMalik
User
Posts: 11
Joined: 11-Oct-2011
# Posted on: 29-Jan-2013 19:10:55   

Hi Devex wpf controls expose a validate event as shown below:

private void dxTextEdit_Validate(object sender, DevExpress.Xpf.Editors.ValidationEventArgs e) { if (e.Value == null) return; if (e.Value.ToString().Length > 4) return; e.IsValid = false; e.ErrorType = DevExpress.XtraEditors.DXErrorProvider.ErrorType.Information; e.ErrorContent = "User ID is less than five symbols. Please correct."; }

This can be used for custom validation ... good for custom validation on the front end.

But these controls are not picking up the validation logic coded in llblgen validator class! It works fine in windows forms but not in wpf.

Can anybody share a piece of code how the validation can be performed using validator class and the dxTextEdit_Validate event shown above?

Regards

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Jan-2013 06:21:52   

I assume that dxText inherits from TextBox target type. If that is so, you can add you a validation rule in the XAML. See http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=15343&StartAtMessage=0&#85448

At your validator's ValidateFieldValue method you should call something like:

involvedEntity.SetEntityFieldError(OrderFieldIndex.OrderDate.ToString(), ORDER_DATE_ERROR_MESSAGE, false);

If you don't want to use XAML you could do that in code using your dxText.Validate event handler and inspect the involved entity associated to the control and see if there is something in the IDataErrorInfo.

David Elizondo | LLBLGen Support Team
AbbasMalik
User
Posts: 11
Joined: 11-Oct-2011
# Posted on: 30-Jan-2013 18:13:52   

It is very simple because WPF supports IDataErrorInfo now a days. Simply adding the line of code shown in bold worked. Error shows up with error icon and error message in its tooltip.

<dxe:TextEdit EditValue="{Binding Path='SName', Mode=TwoWay,
UpdateSourceTrigger=Default, ValidatesOnDataErrors=True}" CausesValidation="True"/>

Here is an article for reference: http://blogs.msdn.com/b/wpfsdk/archive/2007/10/02/data-validation-in-3-5.aspx

Just posting it here so that it can help someone else ...

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 30-Jan-2013 20:52:13   

Thank you very much. I'm sure this would be useful for many others.