WPF工具包DataGrid列resize事件 [英] WPF Toolkit DataGrid column resize event
问题描述
我使用WPF工具包Datagrid的在我工作的应用程序之一。我要的是存储列宽和的DisplayIndex为用户preference。我已经achived它列的DisplayIndex但调整大小我无法找到列大小的变化之后,将触发数据网格的任何事件。
我曾尝试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 ?
推荐答案
摘自...:
http://forums.silverlight.net/post/602788.aspx
后负荷:
PropertyDescriptor pd = DependencyPropertyDescriptor
.FromProperty(DataGridColumn.ActualWidthProperty,
typeof(DataGridColumn));
foreach (DataGridColumn column in Columns) {
//Add a listener for this column's width
pd.AddValueChanged(column,
new EventHandler(ColumnWidthPropertyChanged));
}
2种方法:
2 methods:
private bool _columnWidthChanging;
private void ColumnWidthPropertyChanged(object sender, EventArgs e)
{
// listen for when the mouse is released
_columnWidthChanging = true;
if (sender != null)
Mouse.AddPreviewMouseUpHandler(this, BaseDataGrid_MouseLeftButtonUp);
}
void BaseDataGrid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (_columnWidthChanging) {
_columnWidthChanging = false;
// save settings, etc
}
}
在ColumnWidthPropertyChanged火灾不断,而用户拖动周围的宽度。添加previewMouseUp处理器可以让你当用户完成过程。
The ColumnWidthPropertyChanged fires constantly while the user drags the width around. Adding the PreviewMouseUp handler lets you process when the user is done.
这篇关于WPF工具包DataGrid列resize事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!