WPF列表视图的columnHeader Click事件 [英] WPF Listview Columnheader Click Event

查看:1199
本文介绍了WPF列表视图的columnHeader Click事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WPF一个ListView(GridView的),我想排序根据的 http://msdn.microsoft.com/en-us/library/ms745786.aspx 。在我的情况下,其中一列的celltemplate包含扩展。现在,当我点击扩展头中,GridViewColumnHeader.Click事件触发。我如何prevent这种情况的发生?

I have a ListView (GridView) in WPF and I'm trying to implement sorting according to http://msdn.microsoft.com/en-us/library/ms745786.aspx. In my case, the celltemplate for one of the columns contains an Expander. Now when I click the expander header, the GridViewColumnHeader.Click event fires. How do I prevent this from happening?

推荐答案

如果没有什么需要发生,以 e.Cancel = TRUE 取消。我有我的,一个项目这样的事情,我不希望用户重新排序列:

If nothing needs to happen, cancel it with e.Cancel = true. I have something like that in a project of mine, where I don't want the user to reorder the columns:

private void DataGrid_ColumnReordering(object sender, Microsoft.Windows.Controls.DataGridColumnReorderingEventArgs e)
{
    e.Cancel = true;
}

然后,在XAML,我有:

Then, in the XAML, I have:

<toolkit:DataGrid ItemsSource="{Binding JournalItems}" 
                  AutoGenerateColumns="True"
                  ColumnReordering="DataGrid_ColumnReordering">

这是WPF工具包数据网格,但 e.Cancel = TRUE 应该适用于任何控制。

This is the WPF Toolkit datagrid, but the e.Cancel = true should work for any control.

如果其他的事情需要当用户点击这个头的事情发生,你也可以处理它的那个方法。

If other things need to happen when the user clicks this header, you can also handle it in that method.

您可以查看发件人,看看那里的用户点击(在扩展还是在GridView的标头),如果你需要以不同方式处理这些案件。如果发件人是扩展,将其取消。如果发件人是gridview的头,让分院继续。

You could check the sender to see where the user clicked (on the expander or on the gridview header) if you need to handle these cases differently. If the sender is the expander, cancel it. If the sender is the gridview header, let the sorting continue.

这篇关于WPF列表视图的columnHeader Click事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆