In this lesson, you will learn how to format data that satisfies the specified criteria. For this purpose, the Conditional Appearance module will be added to the application. You will highlight the DemoTask objects whose Status property is not set to Completed. In addition, you will highlight the Priority property when it contains the High value.
Add the Conditional Appearance module to your MySolution.Module project. For this purpose, double-click the Module.cs (Module.vb) file, located in the MySolution.Module project. The Module Designer will be invoked. In the Toolbox, navigate to the DX.19.2: XAF Modules tab, and drag the ConditionalAppearanceModule item from this tab to the Designer's Required Modules section, as shown below.
Rebuild your solution after you have made changes in the Module Designer.
To declare a conditional appearance rule for the DemoTask class, apply the AppearanceAttribute attribute to this class. As the first parameter, specify the Appearance Rule identifier (e.g., "FontColorRed"). Then, specify the following parameters.
Conditions under which the rule must be in effect.
Set the AppearanceAttribute.Context parameter to "ListView" and the AppearanceAttribute.Criteria parameter to "Status!='Completed'". In this instance, the rule generated from the attribute will be in effect in a DemoTask List View for the object whose Status property is not set to Completed.
Apply the AppearanceAttribute attribute to the DemoTask class' Priority property. As the first positional parameter, specify the Appearance Rule identifier (e.g., "PriorityBackColorPink"). Then, specify the following parameters.
Specify the target UI elements to be affected by the rule
Set the AppearanceAttribute.AppearanceItemType parameter to "ViewItem". This means that the rule generated from the attribute will affect the Priority property displayed in the current View.
Specify the conditions under which the rule must be in effect
Public Class DemoTask
<Appearance("PriorityBackColorPink", AppearanceItemType := "ViewItem", Context := "Any", _
Criteria := "Priority=2", BackColor := "255, 240, 240")> _
Public ReadOnly Property Priority() As Priority
Run the WinForms or ASP.NET application. The DemoTask List View and Detail View data will be highlighted, as demonstrated in the following image.
Appearence Rules that are declared in code are available in the Model Editor. To access them, you can run the Model Editor for the MySolution.Module project. Navigate to the BOModel | DemoTask | AppearanceRules node. This node has two child nodes (FontColorRed and PriorityBackColorPink) that are generated automatically from Appearance attributes applied to the DemoTask class and the DemoTask.Priority property. You can create new Appearance Rules directly in the Model Editor by adding child nodes to the AppearanceRules node.
You can see the changes made in the lesson in the DemoTask.cs (DemoTask.vb) file located in the MainDemo.Module project of the MainDemo solution. The MainDemo application is installed in %PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\MainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/.