Skip to main content
.NET 6.0+

RuleBaseAttribute.CustomMessageTemplate Property

Specifies informational text that is to be added to the exception message when the current Validation Rule is broken.

Namespace: DevExpress.Persistent.Validation

Assembly: DevExpress.Persistent.Base.v23.2.dll


public string CustomMessageTemplate { get; set; }

Property Value

Type Description

A string value that contains information on the current rule.


When a validation rule is broken, an XAF application invokes the error window that displays the information on this broken rule. Each rule has its default message template. The Model Editor IModelValidationDefaultErrorMessageTemplates node lists these default templates:

The IModelValidationDefaultErrorMessageTemplates node in the Model Editor

You can use format items to include property values in the message. A format item is a property path wrapped in curly braces. The property path is resolved from the current rule object. You can use properties of the RuleBase and RuleBaseProperties descendant classes. For example, use the following format items:

The display member of the validated object or its key property value if the display member is not declared.
{TargetObject.<The Object’s Property Name>}
The value of the specified validated object property.
The value of the validated property.
The localized caption of the validated property.
The value to be compared to the target property value. You can only use this format item in CustomMessageTemplate with rules that have the RightOperand property. For example, you can use this item with the following attribute: RuleValueComparison.

How to Customize the Message Template

In the Model Editor

You can customize default messages in the IModelValidationDefaultErrorMessageTemplates child nodes globally for all rules in the application.

To specify a custom message template for a rule, navigate to the Validation | Rules | Rule node and modify its CustomMessageTemplate or MessageTemplate… property:

The MessageTemplateMustNotBeEmpty property

In Code

To set a custom message for a particular rule in code, specify the CustomMessageTemplate parameter of a rule attribute. The following example demonstrates how to use a format item to include the RightOperand value in the validation message:

using DevExpress.Persistent.Validation;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
public class Account : BaseObject {
   [RuleValueComparison("RuleRequiredField for Account .Amount", DefaultContexts.Save,
      ValueComparisonType.LessThan, 100,
      CustomMessageTemplate = "The Amount must not be less than {RightOperand}.")]
   public virtual double Amount { get; set; }

// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.

The CustomMessageTemplate property of the corresponding IModelRuleBase node stores the message template specified for the validation rule attribute in code.


Note that CustomMessageTemplate does not include the list of found objects when you specify this property for the RuleUniqueValueAttribute or inverted RuleIsReferencedAttribute / RuleObjectExistsAttribute. To display this list, specify the MessageTemplateMustBeUnique property instead of CustomMessageTemplate in the corresponding Model Editor nodes.

See Also