Create a ContextMenu from xaml, per DataGrid row #16042
-
Hi, I'm using a DataGrid and I want a different ContextMenu on each row (e.g. depending on the row's DataContext). My current solution is using public void OnDataGridLoadingRow(object? sender, DataGridRowEventArgs e)
{
var cm = new ContextMenu();
var ri = e.Row.DataContext as MainWindowViewModel.RowItem;
cm.Items.Add(new MenuItem() { Header = "thing " + ri.ValueCol1 });
cm.Items.Add(new MenuItem() { Header = "hey" });
e.Row.ContextMenu = cm;
} This works, but I would like to define the Here is minimal full code
Is there a better approach than using |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can add a Style for |
Beta Was this translation helpful? Give feedback.
You can add a Style for
DataGridRow
which hold a ContextFlyout iirc.