gpt4 book ai didi

c# - DataGrid WPF 中的 DataGridTemplateColumn 列跨度

转载 作者:行者123 更新时间:2023-11-30 17:36:44 24 4
gpt4 key购买 nike

我正在制作如下图所示的 UI。

DataGrid它是一个DataGrid,Itemsource 绑定(bind)到一个List。我无法为 TextBox 设置 ColumnSpan。首先,我尝试使用 UserControl 但我无法修复 DataGridTemplateColumn header ,然后我尝试了 DataGridTemplateColumn.CellTemplate 但无法设置 ColumnSpan

有什么办法/方法可以制作这种Datagrid吗?

提前谢谢你。

最佳答案

DataGrid 中没有 ColumnSpan,就像在普通的 Grid 中一样。

要获得这种布局,您有 3 种选择,不幸的是,它们都有严重的缺点。

1个合并单元格

使用合并事件在代码隐藏中将单元格合并在一起。 See a guide to this here这需要后面有一大块代码 编码以使您的布局正确。所以我真的建议 反对这一点。

2 行详细信息

使用 RowDetails 中的构建。这不会使布局与您的布局完全相同,但它是最简单、最接近您要求的内置功能。<​​/p>

它看起来像这样:

Row Template

很容易配置:设置:DataGrid XAML 中的 RowDetailsVisibilityMode="Visible"。并为该行定义模板:

<DataGrid.RowDetailsTemplate>
<DataTemplate>
<TextBlock Text="{Binding Desc}" Background="LightGray"/>
</DataTemplate>
</DataGrid.RowDetailsTemplate>

[+] 所有 DataGrid 功能都可以使用:排序、添加行、调整大小...

[-] 详细信息部分跨越整行。

参见 this tutorial about what you can do with row details.

3 一起破解一些东西

使用模板和代码隐藏。一些可能对您有帮助的资源:

关于c# - DataGrid WPF 中的 DataGridTemplateColumn 列跨度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39071767/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com