AppearanceAttribute.Method Property
Specifies the name of the business class method used to determine whether the Conditional Appearance rule generated from this attribute is currently active.
Namespace: DevExpress.ExpressApp.ConditionalAppearance
Assembly: DevExpress.Persistent.Base.v24.2.dll
NuGet Package: DevExpress.Persistent.Base
Declaration
Property Value
Type | Description |
---|---|
String | A string specifying the name of the method used to determine whether the rule is active. |
Remarks
When you need to create a complex rule that cannot be specified using the AppearanceAttribute.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.
Example
According to the rule demonstrated in the example below, the Product objects in List Views will be displayed in Green background using Black font color when the RuleMethod returns true.
using DevExpress.ExpressApp.ConditionalAppearance;
//...
public class Product : BaseObject {
public virtual decimal Price { get; set; }
public virtual ProductStatus Status { get; set; }
[Appearance("RuleMethod", AppearanceItemType = "ViewItem", TargetItems = "*", Context = "ListView",
BackColor = "Green", FontColor = "Black")]
public bool RuleMethod() {
if (Price < 10 && Status == ProductStatus.Active) {
return true;
}
else {
return false;
}
}
}
// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.
Tip
There are more examples demonstrated in the Declare Conditional Appearance Rules in Code topic. See these examples in the Feature Center demo installed with the XAF in the %PUBLIC%\Documents\DevExpress Demos 24.2\Components\XAF\FeatureCenter.NETFramework.XPO folder, or refer to the Feature Center demo online.
Static Method
The appearance rule is inactive when the target method is non-static and the target object is null. If you declare the method as static, the method can optionally accept a parameter that provides access to the context object:
public static bool MyMethod(object contextObject) {
if(contextObject != null) {
// calculate and return result based on context
}
else {
// return default result
}
}