Skip to main content
.NET 6.0+

AppearanceAttribute.Criteria Property

Specifies the criteria string used when determining whether AppearanceAttribute.TargetItems should be affected by the conditional appearance rule generated from the current attribute.

Namespace: DevExpress.ExpressApp.ConditionalAppearance

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

Declaration

public string Criteria { get; set; }

Property Value

Type Description
String

A string representing the criterion under which the conditional appearance rule is in effect.

Remarks

To learn how to declare string criteria and use Function Criteria Operators in string criteria, refer to the following topics:

When you need to create a complex rule that cannot be specified in the Criteria property, you can implement a business class method that takes no parameters and returns a Boolean value that specifies whether the rule is active. XAF ignores the Criteria property in this case. You do not need to specify the Method parameter if you apply AppearanceAttribute directly to the business class method. For more information, refer to the Method property description.

Delayed Loading and Free Joins in Criteria Expressions

Avoid Delayed Properties and Free Joins in a criteria expression, because AppearanceController calculates the expression during the paint process.

Note

In Windows Forms applications, Delayed Properties and Free Joins may load data from the database during the paint process. This may cause UI flicks or corrupt the state of a Windows Forms control.

Use the following techniques to avoid side effects if you need to include Delayed Properties in a criteria expression:

If the above techniques are not applicable and your app crashes with InvalidOperationException (‘Recursive read not allowed’ or ‘Entering the GetObjectsNonReenterant state is prohibited’), use the solution #4 from the following article: Troubleshooting - How to resolve the “Entering the ‘GetObjectsNonReenterant’ state…” error.

Examples

Example 1

According to the rule demonstrated in the example below, the Category property in List Views will be displayed in Blue font color when its value is “Seafood”.

using DevExpress.ExpressApp.ConditionalAppearance;
//...
[Appearance("CategoryColoredInListView", AppearanceItemType = "ViewItem", TargetItems = "Category",
 Criteria = "Category = 'Seafood'", Context = "ListView", FontColor = "Blue", Priority = 1)]
public class Product : BaseObject {
    public virtual Category Category { get; set; }
}

[DefaultProperty(nameof(Name))]
public class Category : BaseObject {
    public virtual string Name { get; set; }
}

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

Example 2

According to the rule demonstrated in the example below, a Product’s Deactivate Action will be disabled when the Status property is set to “Inactive” in all Product Views. Note that the Action ID specified in this rule contains the class name (“Product.Deactivate”), because the Deactivate Action is declared using the ActionAttribute. If an Action is declared in a Controller, specify its ID without the class name, e.g., “Delete” or “Unlink”.

using DevExpress.ExpressApp.ConditionalAppearance;
//...
[Appearance("ActionState", AppearanceItemType = "Action",
    TargetItems = "Product.Deactivate",
        Criteria = "Status = 'Inactive'", Context = "Any", Enabled = false)]
public class Product : BaseObject {
    public virtual ProductStatus Status { get; set; }
    [Action(PredefinedCategory.RecordEdit, Caption = "Deactivate Product...", AutoCommit = true,
     TargetObjectsCriteria = "Status = 'Active'",
      SelectionDependencyType = MethodActionSelectionDependencyType.RequireSingleObject)]
    public void Deactivate() {
        Status = ProductStatus.Inactive;
    }
}

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

For additional examples, refer to following topic: Declare Conditional Appearance Rules in Code. Try these examples in the Feature Center demo installed with XAF in the %PUBLIC%\Documents\DevExpress Demos 23.2\Components\XAF\FeatureCenter.NETFramework.XPO folder, or refer to the Feature Center demo online.

Implements

See Also