CardItemFormatRule Class
A format rule that is calculated by data items and used to apply conditional formatting to the Card dashboard item.
Namespace: DevExpress.DashboardCommon
Assembly: DevExpress.Dashboard.v24.1.Core.dll
NuGet Package: DevExpress.Dashboard.Core
Declaration
Remarks
You can create a format rule that is calculated by hidden measures and series dimensions. These rules apply to all cards in the Card dashboard item. In code, you can also calculate a format rule by actual and target values. The rule applies to the card by whose value a rule is calculated.
Create the CardItemFormatRule
object and specify its settings to add a format rule:
- Create a condition (the FormatConditionBase descendant), specify its settings, and assign the resulting object to the DashboardItemFormatRule.Condition property.
- Assign a data item (a measure/series dimension) to the CardItemFormatRule.DataItem property. The data item’s value is used to calculate the condition.
Assign the specified CardFormatRuleLayoutElement to the CardItemFormatRuleBase.ApplyToLayoutElement property. This property allows you to select the layout element to apply formatting. A background color applies to all card elements regardless of the selected layout element.
Add the created format rule to the CardItemFormatRuleCollection collection.
The following code snippet illustrates the format rule calculated by the actual value. The rule applies to cards whose actual value is between the Value1 and Value2 values.
using System.Windows.Forms;
using DevExpress.DashboardCommon;
using System.Drawing;
CardDashboardItem card = (CardDashboardItem)dashboardDesigner1.Dashboard.Items["cardDashboardItem1"];
CardItemFormatRule rule = new CardItemFormatRule();
rule.DataItem = card.Cards[0].ActualValue;
rule.ApplyToLayoutElement = CardFormatRuleLayoutElement.ActualValue;
FormatConditionValue value = new FormatConditionValue();
value.StyleSettings = new AppearanceSettings(Color.LightCoral, Color.DarkBlue);
value.Value1 = 50000;
value.Value2 = 70000;
value.Condition = DashboardFormatCondition.Between;
rule.Condition = value;
card.FormatRules.Add(rule);