Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+

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.

Implements

See Also