跨多个 DataGrid 共享 DataGrid 列宽度
我正在一个应用程序中使用相同的列和绑定集创建多个 DataGrid。我希望做的是使所有 DataGrid 对一个 DataGrid 中的更改做出适当的响应。如果我更改一列的大小,其他 DG 中的相应列应具有相同的宽度。这与SO上的这个问题有点相似(WPF share columns width Between alone grids) 除了 DataGrid,而不是 Grid。我希望 DataGrids 有一个类似于 Grid 中的 IsSharedSize 的属性,但情况似乎并非如此。
是否有我可以访问的属性或某种替代方法来完成我想要完成的任务?不过,在有人提出这一点之前,我无法将它们全部合并到一个 DataGrid 中,我正在尝试的意味着由于应用程序本身的性质,我无法将所有信息放入一个 DataGrid 中。
I'm making multiple DataGrids in an application with the same set of columns and bindings. What I'm hoping to do is make all the DataGrid respond appropriately to a change in one DataGrid. If I change the size of one column, the corresponding columns in the other DGs should have the same width. It's somewhat similar to this question on S.O. (WPF share column width between separate grids) except for DataGrids, not Grids. I was hoping DataGrids would have a property similar to IsSharedSize like in Grid but this doesn't seem to be the case.
Is there a property I could access, or some alternative approach, to do what I'm trying to accomplish? Before anyone proposes this though, I cannot merge them all into one DataGrid, what I'm attempting means I can't put all the information in one DataGrid due to the nature of the application itself.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然开箱即用的 DataGrid 无法共享宽度,但我发现这是处理此类情况的最佳方法。
在源
DataGrid
列和目标DataGrid
列宽度之间创建绑定。就我而言,我有两个目标 DataGrid(dgTarget1 和 dgTarget2),因此代码如下:While sharing width is not possible in
DataGrid's
out-of-the-box, this is what I came across as the best way to handle such scenarios.Create bindings between the source
DataGrid
columns and the targetDataGrid
columns widths. In my case I have two targetDataGrid's
(dgTarget1 and dgTarget2), so here is the code:在这个聚会上有点晚了,但我遇到了一个类似的场景,我需要一个网格位于 DataGrid 下方并共享相同的列跨度。您可以仅使用 XAML 实现与 digitalguy 的答案类似的功能:
您没有理由不能使用两个 DataGrid 执行相同的操作。
A bit late to the party on this one, but I came across a similar scenario where I needed a Grid to sit below a DataGrid and share the same column spans. You can implement something similar to digitguy's answer using just XAML:
There's no reason that you couldn't do the same thing with two DataGrids.