BoldDeskWe are launching BoldDesk on Product Hunt soon. Learn more & follow us.
I have a datagrid with ten columns and would like to add a contextmenu specific to each column in XAML, is this possible? I see that the GridDataVisible.ColumnStyle has a ContextMenuItems property, but was not able to figure out how to use it.
Hi Ed
You can
specify ContextMenu for specific columns by handling QueryContextMenuInfo
event. .Please find the code snippet below,
Code Snippet:
List<MenuItem> menuitems = new List<MenuItem>();
public
MainWindow()
{
InitializeComponent();
menuitems.Add(new MenuItem() { Header = "Item
1" });
menuitems.Add(new MenuItem() { Header = "Item
2" });
this.dataGrid1.Model.QueryContextMenuInfo
+= Model_QueryContextMenuInfo;
}
void
Model_QueryContextMenuInfo(object sender, GridQueryContextMenuInfoEventArgs e)
{
var style
= e.Style as GridDataStyleInfo;
if (
style.CellIdentity.Column!=null && style.CellIdentity.Column.MappingName == "SupplierID")
{
e.Style.ContextMenuItems = menuitems;
}
} |
We created a simple sample
regarding this.Please find the attached sample below.
Please let us know if you have any
concern.
Regards
Pradeepa
Hi Ed
Thanks for your update.
Please let us know if you require further assistance.
Regards
Pradeepa