I have a WPF ListView that opens a certain window when double clicked on a certain item inside the list view, but I have a problem. When I double click the GridViewColumn, that also opens up a certain window. Is there a way to detect if the sender is a gridviewColumn or a listView item? Thanks
2 Answers
I assume you're handling the MouseDoubleClick event of the ListView ? Instead, you should handle that event on the ListViewItem, not the ListView itself. You can do that easily by setting the event handler in the ListView's ItemContainerStyle :
...
<ListView ...>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<EventSetter Event="MouseDoubleClick" Handler="YourHandler" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
...
1 Comment
Dave Haynes
I don't think this answers the poster's question, but it answered mine! Thanks!
in your event handler you typically have two arguments, the first is your sender object, the second is your EventArguments object.
you can check the sender object for the type by using the "is" operator:
private void MyEvent(object sender,EventArgs args )
{
if ( sender is GridView ) dothis();
}
6 Comments
Kevin
Sorry, but a gridView is different than a GridViewColumn, I am trying to basically do the Headers, not the grid itself. So that won't work
Muad'Dib
somewhere you must have an event handler that opens the window, yes? in said event handler just check the sender to see what type it is.
slugster
Surely that is just a typo in @Muad's answer? What happens if you have: if (sender as ListViewItem != null) dothis();
Muad'Dib
I'm using the IS operator, not the AS operator
slugster
Yeah, i saw that. I was talking about the type you were comparing the sender to.
|