在 WPF DataGrid 中通过拖放进行分组
我想在列标题上方的现有 WPF DataGrid 中添加一个“放置”区域。在该区域中,我希望允许用户删除表示要分组的列的列标题,并通过从该区域中删除这些列来取消对这些列的分组。 Xceed、SyncFusion 和其他商业网格提供了此功能,但我需要自己完成。
我的方法包括提取 DataGrid 的 ControlTemplate,根据我的需要修改它,然后创建一个派生自 DataGrid 的新控件,该控件在其 generic.xaml 中定义此 ControlTemplate。在大多数情况下,这是可行的,但必须有更好的方法,不是吗?
我正在寻找一种使用附加属性的方法,但无法弄清楚如何将新的“放置”区域插入现有控件的可视化树中。
欢迎任何建议。谢谢!
I want to add a "drop" area to the existing WPF DataGrid, above the column headers. In that area I want to allow the user to drop column headers that represent the columns to be grouped and to ungroup those columns by removing them from this area. Xceed, SyncFusion, and other commercial grids provide this functionality but I need to do it myself.
My approach consisted of extracting the DataGrid's ControlTemplate, modifying it to my needs, and then creating a new control derived from DataGrid which defines this ControlTemplate in its generic.xaml. For the most part this is working but there has to be a better way, is there?
I was looking for an approach that used attached properties but couldn't figure out how to insert the new "drop" area into the existing control's Visual Tree.
Any suggestions are welcomed. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以编写一个包含 DataGrid 并覆盖其 ControlTemplate 的控件,或者如果仅在一个地方使用它,则只需在使用它的地方覆盖它。
然而,封装 DataGrid 而不是继承它并没有多大区别。
You could write a Control that contains a DataGrid and overrides its ControlTemplate, or simply override it in the place you use it, if you only use it in one place.
However, encapsulating the DataGrid instead of inheriting from it wouldn't make that much of a difference.