Dynamically add ContentMenu to DataGrid ColumnHeaderContextMenu

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.
  1. ContextMenu CM = new System.Windows.Controls.ContextMenu();    
  2. DataGridTextColumn dataGridTextColumn = new DataGridTextColumn();    
  3. MenuItem MI = new MenuItem();    
  4.                           MI.Header = "Hide/Show";    
  5. MI.IsCheckable = true;    
  6.                           MI.IsChecked = true;    
  7. TextBlock TB=new TextBlock();    
  8.                           TB.HorizontalAlignment = HorizontalAlignment.Stretch;    
  9.                           TB.VerticalAlignment = VerticalAlignment.Stretch;    
  10.                           TB.Text=field.Name;    
  11.                           TB.ContextMenu=CM;    
  12. dataGridTextColumn.Header =TB;