How to: Support a Context Menu for a Custom WinForms List Editor 如何:支持自定义 WinForms 列表编辑器的上下文菜单

In XAF applications, List Views can have context menus filled with Actions. For this purpose, the List Editor displaying a List View should support the IRequireContextMenu and IRequireDXMenuManager interfaces. This topic describes how to implement these interfaces in the WinCustomListEditor demonstrated in the How to: Implement a Custom WinForms List Editor topic.

在 XAF 应用程序中,列表视图可以具有填充操作的上下文菜单。为此,显示列表视图的列表编辑器应支持"需要上下文菜单"和"需要DXMenuManager"接口。本主题介绍如何在 WinCustomListEditor 中实现这些接口,这些接口在"如何:实现自定义 WinForms 列表编辑器"主题中演示。

The following image illustrates the context menu invoked for the WinCustomListEditor.

下图说明了为 WinCustomListEditor 调用的上下文菜单。

PopupMenuForWinThumbnailEditor

Note 注意
You can see the code implemented here in the FeatureCenter demo installed with XAF. This demo is located in the %PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\FeatureCenter folder by default.
您可以在与 XAF 一起安装的功能中心演示中看到此处实现的代码。此演示位于%PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\FeatureCenter folder by default.

To enable the context menu in a custom List Editor, modify its code in the following manner.

要在自定义列表编辑器中启用上下文菜单,请按以下方式修改其代码。

复制代码
[ListEditor(typeof(IPictureItem))]
public class WinCustomListEditor : ListEditor, /* ...*/ IRequireContextMenu, IRequireDXMenuManager {
    #region IRequireContextMenu Members
    private void BarManager_QueryShowPopupMenu(object sender, QueryShowPopupMenuEventArgs e) {
        if (e.Control != control) {
            e.Cancel = true;
            e.BreakShowPopupMenu = false;
        }
    }
    public void SetMenu(PopupMenu popupMenu, BarManager barManager) {
        barManager.SetPopupContextMenu(control, popupMenu);
        barManager.QueryShowPopupMenu += BarManager_QueryShowPopupMenu;
    }
        #endregion

        #region IRequireDXMenuManager Members
        public void SetMenuManager(IDXMenuManager menuManager) { }
        #endregion
}
复制代码

 

If you implement a List Editor using a descendant of the EditorContainer control, initialize the EditorContainer.MenuManager property in the SetMenuManager method.

如果使用编辑器容器控件的后代实现列表编辑器,则在 SetMenuManager 方法中初始化编辑器容器.MenuManager 属性。

In the QueryShowPopupMenu event handler, you can specify whether or not to cancel showing the context menu for the current region of the control using the e.Cancel parameter. For instance, you can use the following logic for the GridView control.

在 QueryShowPopupMenu 事件处理程序中,可以指定是否取消使用 e.Cancel 参数显示控件当前区域的上下文菜单。例如,您可以将以下逻辑用于 GridView 控件。

GridHitTest hitTest = gridView.CalcHitInfo(gridControl.PointToClient(e.Position)).HitTest;
e.Cancel = !(((hitTest == GridHitTest.Row) || 
    (hitTest == GridHitTest.RowCell) || (hitTest == GridHitTest.EmptyRow) || 
    (hitTest == GridHitTest.RowDetail) || (hitTest == GridHitTest.None)));

 

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