I need to make row-level service calls that can have errors I'd like to incorporate into the DataPresenter's ErrorIcon display, just as with IDataErrorInfo errors. Anyone know how to manually add errors such that they will be displayed by this validation mechanism? My only option appears to be in the RecordUpdating event, and I'd like to be more elegant than MessageBox.Show().
Hello Darryl,
Thank you for your post. I have been looking into and I can suggest you see the sample in the Feature Browser under xamDataGrid / Display / IDataErrorInfo Support section, which shows hot to add ErrorInfo on Cell, Record or Record and Cell level. Please let me know if this helps you or I have misunderstood you in some way.
Looking forward for your reply.
I'd like to revive this thread since I've had time to look into it again. To reiterate, I'd like to use the IDataErrorInfo row-level validation support for resource-intensive validation calls that I cannot place in the IDataErrorInfo.Error() method because it is called too frequently. After some research, I found a way to do what I'd like, but I need some help accessing the validation rule XDG uses (and I assume it's a DataErrorValidationRule in a BindingGroup associated with the grid record).
Here's what I've found to work, given access to the validation rule (admittedly a hack, but worth it to me). I bind a property of the record viewmodel to an innocuous, invisible property in the element with the BindingGroup (in this case the TagProperty of a StackPanel), and create the error. For this to work with XDG, alll I need (I think) is to know how to access the ValidationRule associated with the XDG row-level IDataErrorInfo validation. I believe I could add an invisible field for the token binding expression I need to show the error. I'm open to other suggestions as well.
var error = new ValidationError(sp.BindingGroup.ValidationRules[0], spEmailer.GetBindingBLOCKED EXPRESSION;
Here's the code (something truncated it above):
var error = new ValidationError(sp.BindingGroup.ValidationRules[0], sp.GetBindingBLOCKED EXPRESSION;
var error = new ValidationError(sp.BindingGroup.ValidationRules[0], sp.GetBindingExpresion(StackPanel.TagProperty))
error.ErrorContent = "test error"
Validation.MarkInvalid(sp.GetBindingExpresion(StackPanel.TagProperty), error);
Thanks Stefan, this sounds like a workable approach. I'll get back to this as soon as possible and let you know.
I have contacted with the developer who works on IDataErrorInfo support of the XamDataGrid and he said that you can cache the error information you retrieve on the object that implements IDataErrorInfo and return the cached error information from the IDataErrorInfo.Error property.
You can get the error information asynchronously or whichever way you want – all you need to be done once you get the error information and caches it on the IDataErrorInfo object is for that object is to notify the XDG so the XDG re-queries the Error property and displays the newly available error information in the UI. To have the XDG re-query IDataErrorInfo.Error, have the IDataErrorInfo object send a PropertyChanged notification with string.Empty as the property name.
You have misunderstood, and I believe it's my fault. I apologize. The StackPanel/Tag bit was an illustration of how I can do what I'm requesting outside of XDG (accessing a bindinggroup validationrule with an invisible binding expression to force an error message to the IDataErrorInfo record/group-level error display in code). It was one suggestion of how to do what I originally requested, but in order to do it in XDG, I made some assumptions about IDataErrorInfo record-level validation in XDG (i.e., that XDG uses a bindinggroup and a group validation rule for record-level IDataErrorInfo validation), and based on those assumptions I requested some additional information (i.e., how to access the bindinggroup in XDG). Those assumptions may be invalid.
My original request was to use the IDataErrorInfo row-level validation error display for errors generated outside IDataErrorInfo.Error, when I make resource-intensive service calls that I cannot place inside IDataErrorInfo.Error(), because that interface member is accessed much too frequently in XDG. That might not be possible, as it depends on how record-level IDataErrorInfo validation is implemented in XDG. There are perhaps other ways I can do what I want, if I can have some detail about how this support works in XDG.
This is a bit tedious, and I sympathize. But it's important to my architecture. Please forward this to a developer for input. Thank you.
You can access the DataRecordPresenter of a particular Record by using the DataRecordPresenter static method FromRecord. Once you get it you can use the Utilities class’ GetDescendantFromType or GetDescendantFromName methods to retrieve a visual element from its Template. Here you can read more about this class and its methods:
http://help.infragistics.com/Help/NetAdvantage/WPF/2011.2/CLR4.0/html/InfragisticsWPF4.v11.2~Infragistics.Windows.Utilities.html
This way you will be able to retrieve the StackPanel of each Record and get its Tag which is the Error. Please let me now if this helps you or I have misunderstood you in some way.
There is nothing to send at this point, but please see my descriptions of the task. Since nothing came to mind, would you please forward to a developer to see if this is even possible?