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();   
        }
    }
 }
复制代码

 

posted @   code first life  阅读(266)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端
点击右上角即可分享
微信分享提示