How To Add Different Context Menu For Each Cells In UWP Cellgrid?

Sample date Updated on Nov 24, 2025
context-menu contextmenu grid sfcellgrid uwp uwp-applications

This example demonstrates how to add different context menu for each cells in UWP CellGrid (SfCellGrid).

To load different ContextMenu items for different cells, the CellContextMenuOpening event can be customized. In that event, the CellContextMenu property can be used to assign the custom menu items.

//Event subsciption
grid.CellContextMenuOpening += CellGrid_CellContextMenuOpening;

//Event customization
private void CellGrid_CellContextMenuOpening(object sender, CellContextMenuOpeningEventArgs e)
{
    if (e.Cell.ColumnIndex == 0 && e.Cell.RowIndex > 0) 
        e.CellContextMenu = GetRowCellMenu(); //Gets context menu items for rows.
    else if (e.Cell.RowIndex == 0 && e.Cell.ColumnIndex > 0)
        e.CellContextMenu = GetColumnCellMenu();// Gets context menu items for columns
    else
        e.CellContextMenu = GetCellContextMenu(); //// Gets context menu items for Cells
}

private ContextMenu GetCellContextMenu()
{
    ContextMenu contextMenu = new ContextMenu();
    for (int i = 0; i < 5; i++)
    {
        MenuFlyoutItem query = new MenuFlyoutItem { Text = string.Format("Cell{0}", i), Height = 50, VerticalAlignment = VerticalAlignment.Center };
        contextMenu.Items?.Add(query);
    }
    return contextMenu;
}

Showing context menu on CellGrid

Up arrow