How to: Disable and Hide Property Editors Based on a Business Rule 如何:基于业务规则禁用和隐藏属性编辑器
XAF is shipped with the Conditional Appearance module. One of the features provided by this module is an option to disable/enable and show/hide Property Editors based on business rules. This topic contains step-by-step instructions that demonstrate how the Conditional Appearance module can be used for this purpose. Several appearance rules will be created to dynamically hide and disable Property Editors.
XAF 随条件外观模块一起提供。此模块提供的功能之一是禁用/启用和显示/隐藏基于业务规则的属性编辑器的选项。本主题包含分步说明,演示如何将条件外观模块用于此目的。将创建多个外观规则来动态隐藏和禁用属性编辑器。
Tip 提示
A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E1672
完整的示例项目可在 DevExpress 代码示例数据库中找到,http://www.devexpress.com/example=E1672
Note 注意
See more examples on how to use the Conditional Appearance in the Feature Center demo installed with XAF, or refer to the Feature Center demo online
请参阅有关如何使用与 XAF 一起安装的功能中心演示中的"条件外观"的更多示例,或在线参阅功能中心演示
Create a new XAF Solution using the DevExpress v19.2 XAF Solution Wizard template. Add the Conditional Appearance module to the module and Mobile module project. To do this, invoke the Module Designer for the module (Mobile module) project and drag the ConditionalAppearanceModule (ConditionalAppearanceMobileModule) item from the Toolbox to the Required Modules panel.
使用 DevExpress v19.2 XAF 解决方案向导模板创建新的 XAF 解决方案。将条件外观模块添加到模块和移动模块项目。为此,请调用模块(移动模块)项目的模块设计器,并将条件外观模块(条件外观移动模块)项从工具箱拖动到"必需模块"面板。
Declare the Contact business class in the solution's Module Project. You can use the XPO Business Object template for this purpose. Replace the auto-generated class' code with the following.
在解决方案的模块项目中声明联系人业务类。为此,您可以使用 XPO 业务对象模板。将自动生成的类代码替换为以下内容。
[DefaultClassOptions] [ImageName("BO_Person")] public class Contact : BaseObject { public Contact(Session session) : base(session) { } public string Name { get { return GetPropertyValue<string>(nameof(Name)); } set { SetPropertyValue<string>(nameof(Name), value); } } public bool IsMarried { get { return GetPropertyValue<bool>(nameof(IsMarried)); } set { SetPropertyValue<bool>(nameof(IsMarried), value); } } public string SpouseName { get { return GetPropertyValue<string>(nameof(SpouseName)); } set { SetPropertyValue<string>(nameof(SpouseName), value); } } public string Address1 { get { return GetPropertyValue<string>(nameof(Address1)); } set { SetPropertyValue<string>(nameof(Address1), value); } } public string Address2 { get { return GetPropertyValue<string>(nameof(Address2)); } set { SetPropertyValue<string>(nameof(Address2), value); } } }
The sample Contact class contains five properties: Name, IsMarried, SpouseName, Address1, Address2.
示例联系人类包含五个属性:名称、已婚、配偶姓名、地址1、地址2。
To ensure that the SpouseName Property Editor is only displayed when a contact is married, add the following AppearanceAttribute attribute. The IsMarried property should be decorated by the ImmediatePostDataAttribute attribute to ensure that the SpouseName Property Editor is immediately hidden when a user changes the IsMarried value.
要确保配偶姓名属性编辑器仅在联系人结婚时显示,请添加以下外观属性属性。IsMarried 属性应由"立即发布数据属性"属性进行修饰,以确保当用户更改 Ismarried 值时,配偶姓名属性编辑器会立即隐藏。
using DevExpress.ExpressApp.ConditionalAppearance; using DevExpress.ExpressApp.Editors; //... [ImmediatePostData] public bool IsMarried { // ... } [Appearance("Single", Visibility = ViewItemVisibility.Hide, Criteria = "!IsMarried", Context="DetailView")] public string SpouseName { // ... }
The appearance rule, declared by the following attribute, ensures that the Address2 Property Editor is enabled only if the Address1 field is filled. Otherwise, the Address2 Property Editor should is disabled.
外观规则由以下属性声明,可确保仅在填充"地址 1"字段时启用地址 2 属性编辑器。否则,应禁用地址 2 属性编辑器。
[ImmediatePostData] public string Address1 { // ... } [Appearance("AddressOneIsEmpty", Enabled = false, Criteria = "IsNullOrEmpty(Address1)", Context="DetailView")] public string Address2 { // ... }
XAF开发成品案例参考
如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。
作者博客: http://www.cnblogs.com/foreachlife
欢迎加入CIIP框架\XAF技术应用交流群: 336090194 群文件中有更多相关工具及文档资料
转载请注明出处。多谢!
欢迎加我微信: admiralcn 或扫码: