在运行时更改WPF的DataGrid中的行的ColumnSpan [英] Changing ColumnSpan for a row in DataGrid of WPF at runtime
问题描述
我有一个数据网格,其中包含一些从数据表绑定的数据,如:
描述|值1 | Value2
个人详细信息| |
名称| Xyz | Abc
年龄| 20 | 12
职业|学生|员工
家庭详情:| |
父亲| Aaa | Bba
儿童| 1 | 2
它有3列。当其他2列没有任何数据时,我想将其他2列与第1列合并(特定行应该只有一列)。喜欢:
描述| Value1 | Value2
个人详细信息:
名称| | Xyz | Abc
年龄| 20 | 12
职业|学生|员工
家庭详情:
父亲| Aaa | Bba
儿童| 1 | 2
是否可以使用数据网格或任何其他控件?
Hi,
I have a datagrid containing some data which is bind from a data table like:
Description | Value1 | Value2
Personal Details | |
Name | Xyz |Abc
Age |20 |12
Occupation |Student |Employee
Family Details: | |
Father |Aaa |Bba
Children |1 |2
It is having 3 columns. I want to merge the 2 other columns with 1st column when 2 other columns doesn''t have any data(The particular row should only have a single column). Like:
Description |Value1 |Value2
Personal Details:
Name |Xyz |Abc
Age |20 |12
Occupation |Student|Employee
Family Details:
Father |Aaa |Bba
Children |1 |2
Can it be done with data grid or with any other control?
推荐答案
你好。你必须定义这样的元素样式:
Hi.You must define element style like this :
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding Subject}" Value="{x:Null}">
<Setter Property="Width" TargetName="NameDataGridColumn" Value="0"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
并且您还必须设置Header =。我希望这个解决方案可以帮到你。
祝你好运
and also you must set Header="". I hope this solution help you.
Good Luck
这篇关于在运行时更改WPF的DataGrid中的行的ColumnSpan的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!