.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET 5.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.v21.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 articles:

When you need to create a complex rule that cannot be specified using the Criteria property, you can implement a business class method that takes no parameters and returns a Boolean value specifying whether the rule is currently active (the Criteria will be ignored in this case). You do not need to specify the Method parameter when the AppearanceAttribute attribute is directly applied to the business class method. Refer to the Method property description for details.

Delayed Loading and Free Joins in Criteria Expressions

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

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 WinForms 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 this 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 Product(Session session) : base(session) { }
    public Category Category {
        //...
    }
}
[DefaultProperty(nameof(Name))]
public class Category : BaseObject {
    public Category(Session session) : base(session) {}
    public string Name {
        //...
    }
}

Example 2

According to the rule demonstrated in the example below, a Product’s Deactivate Action will be hidden 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("ActionVisibility", AppearanceItemType = "Action",
    TargetItems = "Product.Deactivate",
        Criteria = "Status = 'Inactive'", Context = "Any", Visibility = ViewItemVisibility.Hide)]
public class Product : BaseObject {
    public Product(Session session) : base(session) { }
    public ProductStatus Status {
        //...
    }   
    [Action(PredefinedCategory.RecordEdit, Caption = "Deactivate Product...", AutoCommit = true,
     TargetObjectsCriteria = "Status = 'Active'",
      SelectionDependencyType = MethodActionSelectionDependencyType.RequireSingleObject)]
    public void Deactivate() {
        Status = ProductStatus.Inactive;
    }
}

You can find more examples in the Declare Conditional Appearance Rules in Code topic. See these examples in the Feature Center demo installed with the eXpressApp Framework in the %PUBLIC%\Documents\DevExpress Demos 21.2\Components\eXpressApp Framework\FeatureCenter folder, or refer to the Feature Center demo online.

The following code snippets (auto-collected from DevExpress Examples) contain references to the Criteria property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

Implements

See Also