0

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 2

3

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>
...
Sign up to request clarification or add additional context in comments.

1 Comment

I don't think this answers the poster's question, but it answered mine! Thanks!
0

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

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
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.
Surely that is just a typo in @Muad's answer? What happens if you have: if (sender as ListViewItem != null) dothis();
I'm using the IS operator, not the AS operator
Yeah, i saw that. I was talking about the type you were comparing the sender to.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.