// show the context menu void ShowContextMenu(MouseEventArgs e) { // create context menu var ctxMenu = new ContextMenu(); // check what type of cell was clicked to show the right menu var ht = _flex.HitTest(e); switch (ht.CellType) { // if the click was on the column headers, show column picker case CellType.ColumnHeader: { CreateColumnPickerMenu(ctxMenu); break; } // show clipboard menu if the click was on a regular cell case CellType.Cell: { // select cell if not yet selected if (!_flex.Selection.Contains(ht.CellRange)) { _flex.Select(ht.CellRange, false); } CreateClipboardMenu(ctxMenu); break; } } // show the menu var pt = e.GetPosition(LayoutRoot); Point offset = new Point(pt.X, pt.Y); ctxMenu.InvalidateMeasure(); ctxMenu.InvalidateArrange(); ctxMenu.IsOpen = true; }