First, you add a template column
<DataGrid.Columns> <datagridtemplatecolumn header="ComboBox Template Column"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <combobox itemssource="{Binding Source={staticresource Resourcekey=selectedtyperesource}}"Displaymemberpath="Element[itemname]. Value"text="{Binding Element[selectedtype]. Value, Mode=twoway, updatesourcetrigger=propertychanged}"></ComboBox> </DataTemplate> </datagridtemplatecolumn. Celltemplate> </DataGridTemplateColumn> </DataGrid.Columns>
Declare an array of ComboBox drop-down menu bound content
Public Staticxelement[] Selectedtyperesource =Newxelement[] {NewXElement ("Item",NewXElement ("ItemName","Drop-down menu one"),NewXElement ("ItemCode",1)),NewXElement ("Item",NewXElement ("ItemName","Drop-down menu two"),NewXElement ("ItemCode",2))};
Add a local resource dictionary to the constructor
Public MainWindow () {InitializeComponent ();(this. resources["" as ObjectDataProvider). ObjectInstance = Selectedtyperesource;}
Inside the designer
<window.resources><objectdataprovider x:key=""></objectdataprovider ></Window.Resources>
DataGrid Add ComboBox Template Column