문제

Is it possible to identify which window/usercontrol owns a FrameworkElement?

Thank you.

도움이 되었습니까?

해결책

You can "walk up" using the .Parent-Property until you find the window or usercontrol. Just check the type of the parent while walking up.

다른 팁

Or you could just use the static helper method GetWindow(DependencyObject dependencyObject) from the Window class. This method returns the Window object that hosts the element.

While Fischermaen's answer works for most cases, it'd break if you have templates in your code. In that case, you'd have to check both, .Parent and .TemplatedParent when you traverse upward

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