WPF Listview : Column reorder event?

后端 未结 1 759
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-06 15:29

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.

For the moment I just did a

1条回答
  •  情深已故
    2021-01-06 16:21

    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);
        }
    }
    

    0 讨论(0)
提交回复
热议问题