Reputation: 161
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
Upvotes: 0
Views: 2203
Reputation: 292465
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>
...
Upvotes: 3
Reputation: 29226
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();
}
Upvotes: 0