expressappframework-devexpress-dot-expressapp-dot-conditionalappearance-dot-appearanceattribute.md
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.v25.2.dll
NuGet Package : DevExpress.Persistent.Base
public string Method { get; set; }
Public Property Method As String
| Type | Description |
|---|---|
| String |
A string specifying the name of the method used to determine whether the rule is active.
|
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
The following code snippet changes the Product objects in List Views to black on a green background 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.
using DevExpress.ExpressApp.ConditionalAppearance;
//...
public class Product : BaseObject {
public Product(Session session) : base(session) { }
public decimal Price {
//...
}
public ProductStatus Status {
//...
}
[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;
}
}
}
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 25.2\Components\XAF\FeatureCenter.NET.XPO folder, or refer to the Feature Center demo online.
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
}
}
See Also