WPF列表视图:列重新排序的事件吗? [英] WPF Listview : Column reorder event?
问题描述
我需要同步2列表视图事件的列顺序,当用户更改的顺序。但似乎没有一个列重新排序的事件。
I need to sync the column order of two ListViews event when the user changes the order. But it seems there is not a Column reorder event.
有关的那一刻我只是做了AllowsColumnReorder =假,但不是长久之计。虽然搜索网,我发现很多人有同样的问题,但没有解决办法。有什么可以做?
For the moment I just did a AllowsColumnReorder="False" but that is not a permanent solution. While searching the net I found many people with the same problem but no solution. What can be done?
推荐答案
我不知道它的工作原理,但你可能可以采取的事实,即 GridView.Columns
是的ObservableCollection
:您可以订阅 CollectionChanged
事件和处理的情况下,其中动作
= 移动
I'm not sure it works, but you could probably take advantage of the fact that GridView.Columns
is an ObservableCollection
: you could subscribe to the CollectionChanged
event and handle the case where Action
= Move
GridView gridView = (GridView)listView.View;
gridView.Columns.CollectionChanged += gridView_CollectionChanged;
private void gridView_CollectionChanged(object sender, CollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Move)
{
string msg = string.Format("Column moved from position {0} to position {1}", e.OldIndex, e.NewIndex);
MessageBox.Show(msg);
}
}
这篇关于WPF列表视图:列重新排序的事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!