문제

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

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top