简体   繁体   English

停止对WPF dataGrid进行排序

[英]Stop sorting of WPF dataGrid once

I want to show a new window over the position of the column I clicked. 我想在单击的列的位置上显示一个新窗口。 In the window will be decided, if either the content of the dataGrid gets filtered or the dataGrid will be sorted by the clicked column. 在窗口中,将决定是过滤dataGrid的内容还是按单击的列对dataGrid进行排序。

When the ColumnHeader of a dataGrid is clicked the content in the dataGrid gets sorted by default. 单击dataGrid的ColumnHeader时,默认情况下将对dataGrid中的内容进行排序。 I tried to setting the "CanUserSortColumns"-property of the dataGrid to false. 我试图将dataGrid的“ CanUserSortColumns”属性设置为false。 But I cant find an event that triggers after the sorting of the dataGrid to enable the sorting again. 但是我找不到在对dataGrid进行排序后触发的事件以再次启用排序。 I have tried Click, PrewievMouseUp, MouseUp, Loaded and TargetUpdated so far. 到目前为止,我已经尝试了Click,PrewievMouseUp,MouseUp,Loaded和TargetUpdated。

The "Click" event of the ColumnHeader will still trigger, so I could enable the sorting, but if "CanUserSortColumns" is disabled, there is no sufficient visual Indicator while hovering the ColumnHeader. ColumnHeader的“ Click”事件仍将触发,因此我可以启用排序,但是如果禁用了“ CanUserSortColumns”,则在将ColumnHeader悬停时没有足够的可视指示符。

Try to use Sorting event: 尝试使用Sorting事件:

DataGrid.Sorting += DataGridOnSorting;

And put your window logic in handler: 并将您的窗口逻辑放入处理程序中:

private void DataGridOnSorting(object sender, DataGridSortingEventArgs e)
{
    // Your window logic.
    e.Handled = true;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM