开发者

WPF Listview Columnheader Click Event

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?


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

Then, in the XAML, I have:

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

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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜