Domanda

Very simple question.

I have attached to the PreviewMouseLeftButtonDown event. I know this event Tunnels so the first item in the visual tree is going to get flagged as the e.OriginalSource.

Example:

I have a Grid named "MainGrid". This Grid contains a label.

If I setup a PreviewMouseLeftButtonDown event on that grid and I click on the the label, the PreviewMouseLeftButtonDown event will be triggered.

The MouseButtonEventArgs for this contains an OriginalSource (e.OriginalSource). Depending on where I click inside of the label, this might be a border...this might be a textblock or this might be a border.

I want to walk the visual tree and find "MainGrid". I know of the recursive ways to do this, but what if I don't know the type of the owner. I only know I want to find the owner (i.e. this needs to be generic).

Something like "e.OriginalSource.ORIGINAL_OWNER"

Will gladly elaborate if this is not clear.

Thanks

È stato utile?

Soluzione

It sounds like you are just looking for e.Source?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top