Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
910
How to add Item to Context Menus for Cells?
posted

Hello Everyone,

 Ive been playing around with the context menu, I figure out how to add custom context menu to the Grid itself.

But,  I need to have cell level context menu that are context sensitive.

I need to beable to evaluate the value of the cell, and then give it a context menu based on the value.

Since its going to done on the fly, I dont think I can do it in Xaml.  

My scenerio is:

The user right clicks a cell and if it has data, I give it an option to move the value.

They can now right click another cell, and I can give them an option to apply the move, or give them an option to merge the value into the current cell.

The cell will be Numeric in type.

Any help would be appreciated !

 Thanks

DK 

Parents
No Data
Reply
  • 4850
    Offline posted

    Probably the easiest way is to register a class handler in a static constructor, e.g.

    static Window1()

    {

    EventManager.RegisterClassHandler(typeof(CellValuePresenter), FrameworkElement.ContextMenuOpeningEvent, new ContextMenuEventHandler(OnCellContextMenuOpening));

    }

    private static void OnCellContextMenuOpening(object sender, ContextMenuEventArgs e)

    {

    CellValuePresenter cvp = sender as CellValuePresenter;ContextMenu menu = new ContextMenu();

    cvp.ContextMenu = menu;

    }

Children