WPF 工具包 DataGrid 列调整大小事件
我正在我正在开发的应用程序之一中使用 WPF Toolkit Datagrid。我想要的是将列宽和显示索引存储为用户首选项。我已经为列显示索引实现了它,但对于调整大小,我在数据网格上找不到任何事件,该事件将在列大小更改后触发。 我尝试过“SizeChanged”事件,我想该事件仅在最初计算大小时才会触发,并且该事件也是针对整个数据网格而不是针对各个列。
有什么替代解决方案或者是否有人知道该事件?
I am using WPF Toolkit Datagrid in one of the applications I am working on. What I want is to store the column width and displayindex as a user preference. I have achived it for column displayindex but for resize I could not find any event on the datagrid which will trigger after column size change.
I have tried the "SizeChanged" event which I guess is only fired when it is initially calculating the size and that too is for the whole datagrid and not for the individual columns.
Any alternate solution or if anybody knows about the event ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
取自...:
http://forums.silverlight.net/post/602788.aspx< /a>
加载后:
2 种方法:
当用户拖动宽度时,ColumnWidthPropertyChanged 会不断触发。添加 PreviewMouseUp 处理程序可以让您在用户完成操作时进行处理。
taken from... :
http://forums.silverlight.net/post/602788.aspx
after load :
2 methods:
The ColumnWidthPropertyChanged fires constantly while the user drags the width around. Adding the PreviewMouseUp handler lets you process when the user is done.
布局更新了吗?
我在 Silverlight 中工作,网格每秒都会反弹/刷新。
我正在使用 LayoutUpdated 方法,该方法会为每个布局更新事件触发。
您可以保留列宽的字典并检查增量。然后您就会知道哪些列已更改。
LayoutUpdated?
I'm working in Silverlight, and the grid is rebound/refreshed every second.
I'm using the LayoutUpdated method, which fires for every layout updating event.
You could keep a dictionary of the column widths and check for deltas. Then you would know which column(s) had changed.
您可以尝试扩展
DataGrid
,然后实现NotifyPropertyChange
事件。像这样的事情:从那里,您可以向处理程序添加一个延迟来执行您想要它执行的任何操作。类似于:
现在您有了延迟,您可以定义当列宽更改时您想要发生的情况:
您会注意到我正在检查哪个属性已更改。我设置它的方式是这样的,您可以扩展其他属性并为它们的更改创建处理程序。如果您需要多个处理程序,最好创建一个
DataGridPropertyChanged
方法来切换更改的属性。然后,它会为每个发生更改的属性调用适当的方法(例如ColumnWidthChanged
)。这样,您就不必检查每个处理程序是否只修改一个属性。您没有指定语言,所以我将其重新标记为 C#。但是,如果您正在使用 VB,那么它应该足够简单,可以转换为 VB。
希望这有帮助!
You could try extending
DataGrid
and then implementing aNotifyPropertyChange
event. Something like this:From there, you can add a delagate to the handler to do whatever you want it to do. Something like:
Now that you have the delagate, you can define what you want to happen when the column width is changed:
You'll notice that I'm checking for which property was changed. The way I set it up is such that you can extend other properties and make handlers for their change as well. If you want more then one handler, it would probably be best to make a
DataGridPropertyChanged
method that switches on which property was changed. It would then call the appropriate method (such asColumnWidthChanged
) for each property that gets changed. That way, you wont have to be checking that each handler only modifies one property.You didn't specify a language, so I re-tagged this to C#. However, it should be simple enough to transpose to VB if that's what you're using.
Hope this helps!
我假设您想要保存列宽,以便下次启动应用程序时使用相同的列宽来生成数据网格。
如果是这种情况,那么另一种方法是在应用程序关闭时保存列宽度(和索引),这也比每次调整列大小时保存宽度更有效。
根据您的应用程序的结构,类似的东西应该可以工作......
I assume you want to save the column widths so that the next time the application is started those same column widths are used to generate the data grid.
If that's the case then an alternative is to save the column widths (and indexes) when the application is closing, which would also be more efficient than saving the widths every time a column is resized.
Depending on how your application is structured, something like this should work...