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 @ 2020-01-07 11:40  code first life  阅读(196)  评论(0编辑  收藏  举报