Highlight Property Editors(突出显示属性编辑器)
This lesson explains how to format data that satisfies the specified criteria.
本课介绍如何格式化满足指定条件的数据。
The instructions below show how to do the following:
以下说明显示了如何执行以下操作:
- Add the Conditional Appearance module to the application.(将条件外观模块添加到应用程序。)
- *Highlight the DemoTask objects whose Status property is not set to Completed.(*突出显示状态属性未设置为已完成的DemoTask对象。)
- Highlight the Priority property when it contains the High value.(当优先级属性包含高值时,突出显示它。)
Step-by-Step Instructions(分步说明)
1.Add the DevExpress.ExpressApp.ConditionalAppearance NuGet package to the MySolution.Module project. See the following topic for more information on how to install DevExpress NuGet packages: Choose Between Offline and Online DevExpress NuGet Feeds.
将DevExpress. ExpressApp.ConditionalAppearanceNuGet包添加到MySolutions.Module项目。有关如何安装DevExpress NuGet包的更多信息,请参阅以下主题:在离线和在线DevExpress NuGet Feeds之间进行选择。
2.In the MySolution.Module project, open the Module.cs file and add the Conditional Appearance module:
在MySolutions. Module项目中,打开Module.cs文件并添加条件外观模块:
C#
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Updating;
namespace MySolution.Module;
public sealed class MySolutionModule : ModuleBase {
public MySolutionModule() {
// ...
RequiredModuleTypes.Add(typeof(DevExpress.ExpressApp.ConditionalAppearance.ConditionalAppearanceModule));
}
//...
}
3.Open the DemoTask class and apply the AppearanceAttribute attribute as displayed in the code sample below:
打开DemoTask类并应用外观属性,如下面的代码示例中所示:
C#
// ...
using DevExpress.ExpressApp.ConditionalAppearance;
namespace MySolution.Module.BusinessObjects {
[Appearance("FontColorRed", AppearanceItemType = "ViewItem", TargetItems = "*",
Context = "ListView", Criteria = "Status!='Completed'", FontColor = "Red")]
[DefaultClassOptions]
[ModelDefault("Caption", "Task")]
public class DemoTask : BaseObject {
// ...
}
}
The first parameter of the Appearance attribute is Id — a unique appearance rule identifier. The rest of the parameters are as follows:
外观属性的第一个参数是Id——一个唯一的外观规则标识符。其余参数如下:
Note
Follow the Criteria Language Syntax rules to specify the Criteria value.
按照条件语言语法规则指定条件值。
4.Apply the AppearanceAttribute attribute to the Priority property of the DemoTask class. As the first positional parameter, specify the Appearance Rule identifier (e.g., PriorityBackColorPink). Then, specify other parameters.
将外观属性应用于DemoTask类的优先级属性。作为第一个位置参数,指定外观规则标识符(例如PriorityBackColorPink)。然后,指定其他参数。
C#
using DevExpress.ExpressApp.ConditionalAppearance;
//...
public class DemoTask : BaseObject {
// ...
[Appearance("PriorityBackColorPink", AppearanceItemType = "ViewItem",
Context = "Any", Criteria = "Priority=2", BackColor = "255, 240, 240")]
public virtual Priority Priority { get; set; }
// ...
}
The first parameter of the Appearance attribute is once again Id — a unique appearance rule identifier. The rest of the parameters are as follows:
外观属性的第一个参数再次是Id——一个唯一的外观规则标识符。其余参数如下:
5.Run the application. The DemoTask List View and Detail View display a conditional appearance:
运行应用程序。DemoTask List View和Detail View显示条件外观:
ASP.NET Core Blazor
Windows Forms
Note
You can access these appearance rules from the Model Editor. Open the Model.DesignedDiffs.xafml file and navigate to the BOModel | DemoTask | AppearanceRules node. This node has two child nodes: FontColorRed and PriorityBackColorPink. XAF generates them automatically from the Appearance attributes applied to the DemoTask class and the DemoTask.Priority property. To create a new appearance rule in the Model Editor, add a child node to the AppearanceRules node.
您可以从模型编辑器访问这些外观规则。打开Model. DesignedDiffs.xafml文件并导航到BOModel|DemoTask|外观规则节点。该节点有两个子节点:FontColorRed和PriorityBackColorPink。XAF会根据应用于DemoTask类的外观属性和DemoTask.优先属性自动生成它们。要在模型编辑器中创建新的外观规则,请向外观规则节点添加一个子节点。
Next Lesson(下一课)
Attach Files to Objects
将文件附加到对象