Introduction
WPF directly not allowing to add ContextMenuto datagrid column header, but there is a alternate way to to do this. below code explains how to add ContextMenuto datagird columnheader.
ContextMenu CM = new System.Windows.Controls.ContextMenu();
DataGridTextColumn dataGridTextColumn = new DataGridTextColumn();
MenuItem MI = new MenuItem();
MI.Header = "Hide/Show";
MI.IsCheckable = true;
MI.IsChecked = true;
TextBlock TB=new TextBlock();
TB.HorizontalAlignment = HorizontalAlignment.Stretch;
TB.VerticalAlignment = VerticalAlignment.Stretch;
TB.Text=field.Name;
TB.ContextMenu=CM;
dataGridTextColumn.Header =TB;