RuleIsReferencedAttribute.MessageTemplateMustBeReferenced Property
Specifies the text to be written in the Validation Error window when the current rule is broken.
Namespace: DevExpress.Persistent.Validation
Assembly: DevExpress.Persistent.Base.v24.1.dll
NuGet Package: DevExpress.Persistent.Base
Declaration
Property Value
Type | Description |
---|---|
String | A string value representing the text to be written to the Validation Error window when a rule is broken. |
Remarks
When defining a RuleIsReferenced via the RuleIsReferencedAttribute in code or in the Model Editor, you may need to invert it (see RuleBaseAttribute.InvertResult), so that it is broken when objects that reference the current object are found. In this instance, you should write a custom definition to be displayed in the Vaidation Error window for the broken rule. To do this, set the CustomMessageTemplate property. However, the list of found objects will not be displayed. To display them, specify the MessageTemplateMustBeReferenced property instead of the CustomMessageTemplate property. The following code demonstrates this:
[RuleIsReferenced("ComplexValidationSettingsObject_RuleIsReferenced",
DefaultContexts.Delete, typeof(ComplexValidationSettingsObject),
"ReferencedObject", MessageTemplateMustBeReferenced =
"To delete the '{TargetObject}' object, you must be sure that it is not referenced anywhere.",
InvertResult = true)]
public class ComplexValidationSettingsObject : BaseObject {
//...
}
This code is taken from the FeatureCenter demo that illustrates all the capabilities of the Validation module. This demo is located in the %PUBLIC%\Documents\DevExpress Demos 24.1\Components\XAF\FeatureCenter.NETFramework.XPO folder, by default.
To customize the format that is used to list the found objects in the Validation Error window, use the RuleIsReferencedAttribute.FoundObjectMessageFormat and RuleIsReferencedAttribute.FoundObjectMessagesSeparator properties.
As you can see in the code above, the {TargetObject} format item is used in the message template. At runtime, this item will be replaced with the validated object. There is set of format items you can use in message templates. For details, refer to the RuleBaseAttribute.CustomMessageTemplate property description.