How can I get the headerclick event of a WPF Listview?
-
3Seriously! Why couldn't you Google or look at MSDN for this information?!Dennis– Dennis2009-05-22 04:19:11 +00:00Commented May 22, 2009 at 4:19
-
1Yeah hard to disagree, Dennis. I guess because it's "GridViewColumnHeader" it might be a bit hard to search for, but it probably would've been easier than typing in the question and waiting for an answer.Matt Hamilton– Matt Hamilton2009-05-22 04:28:44 +00:00Commented May 22, 2009 at 4:28
-
1If you're pretty new to WPF, it isn't that obvious that the event exists. It's neither in the Properties pane nor in IntelliSense in Visual Studio 2010.matsolof– matsolof2014-09-18 10:53:18 +00:00Commented Sep 18, 2014 at 10:53
Add a comment
|
2 Answers
You can use the GridViewColumnHeader.Click attached event. As an example, see the MSDN page on sorting a GridView when the header is clicked.
<ListView x:Name='lv'
Height="150"
HorizontalAlignment="Center"
VerticalAlignment="Center"
GridViewColumnHeader.Click="GridViewColumnHeaderClickedHandler">
3 Comments
Matt Hamilton
Events that apply to children like that won't show up in Intellisense - the editor can't know which ones you might want to use!
sudarsanyes
worked perfectly and this is how i got the bound column, \string columnProperty = ((Binding)columnHeader.Column.DisplayMemberBinding).Path.Path;
Link is broken. Try this msdn.microsoft.com/en-us/library/ms745786(v=vs.100).aspx
just to expand on the previous answer, how to know which header was clicked on:
XAML:
<ListView GridViewColumnHeader.Click="GridViewColumnHeaderClickedHandler">
CS:
private void SortHeaderClick(object sender, RoutedEventArgs e)
{
MessageBox.Show(((GridViewColumnHeader)e.OriginalSource).Column.Header.ToString());
}
1 Comment
Ivan Silkin
If somebody is searching for the possibility to sort ListView items by ordered LINQ query after acquaring the WPF ListView EventHandler, then there is a compact solution: var query = dataList.OrderByWithDirection(x => x.Property, direction); <stackoverflow.com/questions/388708/…>