如何在WPF DataGrid中合并两个单元格?

问题描述:

我是sarath chandra....

我对wpf很陌生....

我必须在datagrid中显示数据.在这种情况下,我根据条件合并了两个或多个类似Excel的单元格.我必须在后面做代码.


任何机构都可以帮助我........

Hi this is sarath chandra....

I am very much new to wpf.......

I have to display data in datagrid. In that i have merge two or more cells like Excel depending on the condition. I have to do throuh code behind.


Can any body help me........

您在谈论单元"在网格中,您只需要在控件"中根据需要使用"Grid AttachedProperty ColumnSpan"或"RowSpan"即可.

Grid.ColumnSpan =" value "在XAML
Grid.SetColumnSpan( uiElment value )中,在后面的代码中

如果要合并也可以只设置对齐方式直接在控件的VerticalAlignment和Horizo​​ntalAlignment属性中进行设置,因为它将基于封闭的单元格".

You talking about a "cell" in a Grid, you just use Grid AttachedProperty ColumnSpan or RowSpan as needed in the Control that is be placed in the "cell".

Grid.ColumnSpan="value" in XAML
Grid.SetColumnSpan(uiElment, value) in code behind

If you want the merge to also set the alignment just set it directly in the controls VerticalAlignment and HorizontalAlignment properties for it will be base on the enclosing "cell".