Search for WPF merged cells on the Web, has not been searched, no way, can only be done by themselves. Actually is the DataGrid sets the DataGrid, in order to facilitate support column drag, in the merged datagridcolumn that column of the header also put a DataGrid, but the merge of this continuous column supports only one column of drag, the effect is as follows,
The code is as follows
First define two templates, one for the merge header display
<datatemplate x:key= "Mergeheader" > <datagrid horizontalalignment= "Stretch" horizontalgridlinesbrush= "Transparent" borderthickness= "0" margin= "0" canuserreordercolumns= "false" canusersortcolumns= "false" canuserresizecolumns= "False" > <DataGrid.Columns> <datagridtextcolumn header= "Product lot number" Width= "*" isreadonly= "True" /> <datagridtextcolumn header= "Production date" IsReadOnly= " True " width=" /> <datagridtextcolumn header= "valid until" isreadonly= "True" width= "102" / > <datagridtextcolumn header= "TEDSD" width= "126" isreadonly= "True" / > <datagridtextcolumn header= "TESDDFF" width= " isreadonly=" "True"/ > </ datagrid.columns> <DataGrid.Resources> <style targettype= "Datagridcolumnheader" > < Setter property= "Template" value= "{Staticresource stylemergeheader}"/> </ style> </ Datagrid.resources> </datagrid > </DataTemplate>
Another template is used to display the merge details, ItemsSource to bind to a list property of your data source, meaning that you put the merged details into the Sub list property of the main DataGrid data source because the header is not displayed in the details, so hide the header
<datatemplate x:key= "Mergecolumn" > <datagrid name= "Dgmergegrid" itemssource= "{binding meragedata}" Horizontalscrollbarvisibility= "Hidden" verticalscrollbarvisibility= "Hidden" loaded= "dgMergeGrid_ Loaded " borderthickness=" 0,0,0,0 " horizontalalignment=" Center " horizontalcontentalignment=" Center " verticalalignment=" center " verticalcontentalignment=" center " headersvisibility=" None " autogeneratecolumns= "False" isreadonly= "True" > <DataGrid.Columns> < Datagridtextcolumn header= "Product lot number" width= "*" isreadonly= "True" binding= "{binding Producebatchno} "> </datagridtextcolumn> <datagridtextcolumn header= "Production date" isreadonly= "True" width= " " Binding= "{binding producedate}" /> <datagridtextcolumn header= "valid until" isreadonly= "True" width= "102" binding= "{binding expriedate}" /> <datagridtextcolumn header= "Dfafa" width= "126" isreadonly= "True" Binding= "{ Binding smallnum} " /> &nbSp; <datagridtextcolumn header= "FAFSFDFD" width= "" " isreadonly=" True " binding= "{binding packunit}" /> </DataGrid.Columns> <DataGrid.Resources> <style targettype= "DataGrid" > <!--grid Line Color--> < Setter property= "Horizontalgridlinesbrush" > &nBsp; <setter.value> <SolidColorBrush Color= "Transparent"/> </Setter.Value> </Setter> <Setter Property= "Verticalgridlinesbrush" > <setter.value> <solidcolorbrush color= "LightBlue"/> </Setter.Value> </Setter> </Style> </DataGrid.Resources> &lT;/datagrid> </datatemplate>
Then set the template on the column that displays the details in your main DataGrid.
<datagridtemplatecolumn header= "Batch Information" width= "580" headertemplate= "{StaticResource mergeheader} " celltemplate=" {staticresource mergecolumn} "> < datagridtemplatecolumn.headerstyle> <style targettype= " Datagridcolumnheader "> <setter property= " Background " value=" LightBlue "></Setter> </Style> &Nbsp; </datagridtemplatecolumn.headerstyle> </ Datagridtemplatecolumn>
Original link: http://www.cnblogs.com/renzhendewo/p/4238757.html
DataGrid merge Cells (WPF)