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.v22.2.dll
NuGet Package: DevExpress.Persistent.Base
Declaration
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:
- Add a calculated property to a business object and store the calculated value in the database. Refer to the following article for additional information: Calculate a Property Value Based on Values from a Detail Collection.
- Use the SetPrefetchPropertyNames(Object, String[]) method to pre-load collection properties before displaying data on the screen.
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 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.
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 22.2\Components\XAF\FeatureCenter.NETFramework.XPO folder, or refer to the Feature Center demo online.