How to: Support a Context Menu for a Custom WinForms List Editor How to: Support for custom WinForms list editor context menu

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.

In XAF application, the context menu may have a list view of the filling operation. To this end, the list view displays the list editor should support the "need to context menu" and "need DXMenuManager" interface. This topic describes how to implement these interfaces in WinCustomListEditor these interfaces in the "How to: Implement a custom WinForms List Editor" topic in the presentation.

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

The following figure shows the context menu for the WinCustomListEditor call.

PopupMenuForWinThumbnailEditor

Note 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.
You can see the code that implements the functions here in the center of the presentation together with XAF installed in. This demo is located % the PUBLIC% \ Documents \ DevExpress the 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.

To enable the context menu in the 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.

If you use a descendant Editor container control implementation list editor, the editor initialization container .MenuManager property in SetMenuManager method.

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.

In QueryShowPopupMenu event handler, you can specify whether to abolish the use of e.Cancel parameters to display the current area of ​​the control of the context menu. For example, you can use the following logic for the GridView control.

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)));

 

Guess you like

Origin www.cnblogs.com/foreachlife/p/How-to-Support-a-Context-Menu-for-a-Custom-WinForms-List-Editor.html