How to: Customize the New Action's Items List 如何:自定义新按钮的项目列表
This topic demonstrates how to access the list of business classes added to the NewObjectViewController.NewObjectAction items list in WinForms and ASP.NET applications with the Classic Web UI.
本主题演示如何访问添加到 NewObjectViewController.NewObjectAction 项目列表的业务类,并在 WinForms 中列出,并ASP.NET使用经典 Web UI 的应用程序。
Generally, you can use the NewObjectViewController.NewObjectActionItemListMode property to choose the predefined mode of populating the New Action item list. If modes listed in the NewObjectActionItemListMode enumeration do not fit your requirements, proceed to see how to populate the list manually.
通常,您可以使用 NewObjectViewController.NewObjectActionItemListMode 属性选择填充"新建操作项"项列表的预定义模式。如果 NewObjectActionItemListMode 枚举中列出的模式不符合您的要求,请继续了解如何手动填充列表。
To customize the New Action's Items list, handle the NewObjectViewController.CollectDescendantTypes and NewObjectViewController.CollectCreatableItemTypes events of the NewObjectViewController, which contains the New Action. The former event is raised when the current object type and its descendants are added to the Action's Items list, and the latter is raised when all the remaining types whose CreatableItem property is set to true in the Application Model (see IModelBOModel) are added. In the example below, the Task item is removed.
要自定义"新操作"的项目列表,请处理"新对象视图控制器":收集子对象类型和 NewObjectView 控制器。收集包含"新对象视图控制器"的可操作项类型事件。当当前对象类型及其后代添加到操作的"项"列表中时,将引发前一个事件;当添加应用程序模型中的 CreatableItem 属性设置为 true 的所有其余类型(请参阅 IModelBOModel)时,将引发后一个事件。在下面的示例中,任务项将被删除。
Note 注意
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-customize-the-new-actions-items-list-e238
完整的示例项目可在https://github.com/DevExpress-Examples/how-to-customize-the-new-actions-items-list-e238
.
- CustomizeNewActionItemsListController.cs
- CustomizeNewActionItemsListController.vb
- 自定义新操作项列表控制器.vb
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DevExpress.ExpressApp; using DevExpress.Persistent.BaseImpl; using DevExpress.ExpressApp.SystemModule; namespace CustomizeNewActionItemsListExample.Module.Controllers { public class CustomizeNewActionItemsListController : ObjectViewController<ObjectView, Task> { protected override void OnActivated() { base.OnActivated(); NewObjectViewController controller = Frame.GetController<NewObjectViewController>(); if (controller != null) { controller.CollectCreatableItemTypes += NewObjectViewController_CollectCreatableItemTypes; controller.CollectDescendantTypes += NewObjectViewController_CollectDescendantTypes; if (controller.Active) { controller.UpdateNewObjectAction(); } } } private void NewObjectViewController_CollectDescendantTypes(object sender, CollectTypesEventArgs e) { CustomizeList(e.Types); } private void NewObjectViewController_CollectCreatableItemTypes(object sender, CollectTypesEventArgs e) { CustomizeList(e.Types); } private void CustomizeList(ICollection<Type> types) { List<Type> unusableTypes = new List<Type>(); foreach (Type item in types) { if (item == typeof(Task)) { unusableTypes.Add(item); } } foreach (Type item in unusableTypes) { types.Remove(item); } } protected override void OnDeactivated() { NewObjectViewController controller = Frame.GetController<NewObjectViewController>(); if (controller != null) { controller.CollectCreatableItemTypes -= NewObjectViewController_CollectCreatableItemTypes; controller.CollectDescendantTypes -= NewObjectViewController_CollectDescendantTypes; } base.OnDeactivated(); } } }
XAF开发成品案例参考
如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。
作者博客: http://www.cnblogs.com/foreachlife
欢迎加入CIIP框架\XAF技术应用交流群: 336090194 群文件中有更多相关工具及文档资料
转载请注明出处。多谢!
欢迎加我微信: admiralcn 或扫码:

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端