Back to Devexpress

AppearanceAttribute.Context Property

expressappframework-devexpress-dot-expressapp-dot-conditionalappearance-dot-appearanceattribute-71d98fac.md

latest8.2 KB
Original Source

AppearanceAttribute.Context Property

Specifies the Views representing the activity scope for the conditional appearance rule generated from the current attribute.

Namespace : DevExpress.ExpressApp.ConditionalAppearance

Assembly : DevExpress.Persistent.Base.v25.2.dll

NuGet Package : DevExpress.Persistent.Base

Declaration

csharp
public string Context { get; set; }
vb
Public Property Context As String

Property Value

TypeDescription
String

A string that is semicolon separated names of the Views in which the conditional appearance rule is in effect.

|

Remarks

The Context property can have the following values.

ContextAppearance Rule’s Activity ScopeExample
A predefined context - “DetailView”, “ListView” or “Any”.Detail Views, List Views or all Views, respectively.Any
A semicolon-separated list of View identifiers.Specified Views only.MyClass_ListView;MyClass_DetailView
The “Any” predefined context, followed by a semicolon-separated list of View identifiers.All Views except the Views specified via View identifiers.Any;MyClass_ListView;MyClass_LookupListView
The “DetailView” or “ListView” predefined context, followed by a semicolon-separated list of View identifiers.All Detail Views or List Views respectively, in addition to Views specified via View identifiers.DetailView;MyClass_ListView

By default, Context is set to “Any”.

Examples

Example 1

The following code snippet changes the ProductParameters layout group caption in Product Detail Views to blue when the product’s category is “Seafood”:

csharp
using DevExpress.ExpressApp.ConditionalAppearance;
//...
[Appearance("LayoutGroupColoredInDetailView", AppearanceItemType = "LayoutItem",
 TargetItems = "ProductParametersLayoutGroup", Criteria = "Category = 'Seafood'",
 Context = "Product_DetailView", FontColor = "Blue")]
public class Product : BaseObject {
    public virtual string Name { get; set; }
    public virtual decimal Price { get; set; }
    public virtual ProductStatus Status { get; set; }
    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.
csharp
using DevExpress.ExpressApp.ConditionalAppearance;
//...
[Appearance("LayoutGroupColoredInDetailView", AppearanceItemType = "LayoutItem",
 TargetItems = "ProductParametersLayoutGroup", Criteria = "Category = 'Seafood'",
 Context = "Product_DetailView", FontColor = "Blue")]
public class Product : BaseObject {
    public Product(Session session) : base(session) { }
    public string Name {
        //...
    }
    public decimal Price {
        //...
    }
    public ProductStatus Status {
        //...
    }
    public Category Category {
        //...
    }
}
[DefaultProperty(nameof(Name))]
public class Category : BaseObject {
    public Category(Session session) : base(session) {}
    public string Name {
        //...
    }
}

Example 2

The following code snippet changes the Product objects to maroon on a red background in List Views when the product’s price exceeds 50:

csharp
using DevExpress.ExpressApp.ConditionalAppearance;
//...
[Appearance("RedPriceObject", AppearanceItemType = "ViewItem", TargetItems = "*",
    Criteria = "Price>50", Context = "ListView", BackColor = "Red",
        FontColor = "Maroon", Priority = 2)]
public class Product : BaseObject {
    public virtual string Name { get; set; }
    public virtual decimal Price { get; set; }
    public virtual ProductStatus Status { get; set; }
    public virtual Category Category { get; set; }
}

// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.
csharp
using DevExpress.ExpressApp.ConditionalAppearance;
//...
[Appearance("RedPriceObject", AppearanceItemType = "ViewItem", TargetItems = "*",
    Criteria = "Price>50", Context = "ListView", BackColor = "Red",
        FontColor = "Maroon", Priority = 2)]
public class Product : BaseObject {
    public Product(Session session) : base(session) { }
    public string Name {
        //...
    }
    public decimal Price {
        //...
    }
    public ProductStatus Status {
        //...
    }
    public Category Category {
        //...
    }
}

Example 3

The following code snippet disables a Product’s Deactivate Action when the Status property is set to “Inactive” in all Product Views. The Action ID specified in this rule contains the class name (“Product.Deactivate”) because the Deactivate Action is declared using the ActionAttribute. If you declare an Action in a Controller, specify its ID without the class name, for example, “Delete” or “Unlink”.

csharp
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.
csharp
using DevExpress.ExpressApp.ConditionalAppearance;
//...
[Appearance("ActionState", AppearanceItemType = "Action",
    TargetItems = "Product.Deactivate",
        Criteria = "Status = 'Inactive'", Context = "Any", Enabled = false)]
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;
    }
}

Note

When you use a Conditional Appearance Rule (for example, the Appearance attribute) to hide an Action, it remains visible in List Views. XAF displays this Action as disabled. This helps avoid complex calculations that could hinder the application’s performance.

Tip

You can find examples of this functionality in the MainDemo demo included with XAF. The demo illustrates various XAF features (including Appearance attribute) and is located in the %PUBLIC%\Documents\DevExpress Demos 25.2\Components\XAF\MainDemo.NET.EFCore folder.

Implements

Context

See Also

Conditional Appearance (Manage UI State)

AppearanceAttribute Class

AppearanceAttribute Members

DevExpress.ExpressApp.ConditionalAppearance Namespace