DevExpress WPF Grid - 列宽度更改时的事件

发布于 2024-08-13 23:20:00 字数 63 浏览 3 评论 0原文

有谁知道,当用户更改 WPF DevExpress 网格的列宽时会引发哪个事件?我想用它来存储数据库中的列宽度。

does anyone knows, which event is raised, when user changes width of column for WPF DevExpress grid? I want to use it to store columns widths in database.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

温柔一刀 2024-08-20 23:20:00

您可以通过事件 View.LostFocus 存储列宽:

DevExpress.Xpf.Grid.GridControl grc = new DevExpress.Xpf.Grid.GridControl();
grc.View.LostFocus += View_LostFocus;

并与处理程序:

 void View_LostFocus(object sender, RoutedEventArgs e)
  {
        TableView tv = sender as TableView;
        GridColumn[] gcs = tv.VisibleColumns.ToArray();
        foreach (GridColumn gc in gcs)
        {
            if (gc.ActualHeaderWidth != gc.Width)
            {
                double newWidth = gc.ActualHeaderWidth; //Do something with new width
            }
        }
    }

You Can store columns widths by event View.LostFocus:

DevExpress.Xpf.Grid.GridControl grc = new DevExpress.Xpf.Grid.GridControl();
grc.View.LostFocus += View_LostFocus;

And with handler:

 void View_LostFocus(object sender, RoutedEventArgs e)
  {
        TableView tv = sender as TableView;
        GridColumn[] gcs = tv.VisibleColumns.ToArray();
        foreach (GridColumn gc in gcs)
        {
            if (gc.ActualHeaderWidth != gc.Width)
            {
                double newWidth = gc.ActualHeaderWidth; //Do something with new width
            }
        }
    }
樱花坊 2024-08-20 23:20:00

我也必须做同样的事情,但对于 silverlight 网格。我能得到的最好的结果是处理 Grid.LayoutUpdated 事件,并枚举列以获取它们的宽度。我什至无法绑定到 silverlight 网格中的列宽属性,因为它不是依赖属性,WPF 网格很可能完全相同。

编辑:
不过,您可以做的是检查 WPF 网格的源代码,并自己添加 ColumnResized 事件。这并不理想,因为每次安装 DevExpress 更新时都必须重新集成代码,然后重建网格。您还需要小心如何执行此操作,例如,您需要找出最佳方法来确定列大小调整何时完成,以便您不会不断触发该事件。或者您可以寻找一个功能更齐全(更成熟)的网格?

I've had to do the same, but for the silverlight grid. The best i could get was to handle the Grid.LayoutUpdated event, and enumerate the columns to get their widths. I couldn't even bind to the column width property in the silverlight grid because it wasn't a dependency property, the WPF grid is most likely exactly the same.

EDIT:
what you could do though is check through the source code of the WPF grid, and add a ColumnResized event yourself. It's not ideal, because you would have to re-integrate the code everytime you installed a DevExpress update, and then rebuild the grid. You would also need to be careful how you do it, for instance you need to work out the best way to determine when a column resize has finished, so that you don't continually fire the event. Or you could look round for a more fully featured (more mature) grid?

小红帽 2024-08-20 23:20:00

DataGridColumnHeader 公开了一个 SizeChanged 事件,该事件将 SizeChangedEventArgs 对象传递给您,其中公开了许多有用的尺寸信息!

The DataGridColumnHeader exposes a SizeChanged event which passes the SizeChangedEventArgs object to you in which a lot of useful Sizes info is exposed!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文