Is there a way to directly get the Window object a control is on?
Asked
Active
Viewed 533 times
3 Answers
5
Assuming the Control is directly below the Window, you can call GetParent on the LogicalTreeHelper.
You may, of course, need to Use the LogicalTreeHelper
to traverse the tree if the Control is not a direct descendant.

kiwipom
- 7,639
- 37
- 37
-
That's better than what I currently have, but I'm a bit annoyed that there isn't a GetWindow method. – Jonathan Allen Jul 26 '10 at 22:39
1
Most likely you are on the applications active window in the moment you interact with the control.
So in that case, this other post on stackoverflow could be helpful too:

Community
- 1
- 1

SwissCoder
- 2,514
- 4
- 28
- 40
-
That looks like it would be very fragile for my use case, but I;ll give you a point because it would be really useful when displaying a pop-up window with CenterOwner set. – Jonathan Allen Jul 26 '10 at 22:41
0
A bit late, but the following works pretty fine for me.
var ownerWindow = Window.GetWindow(yourControl);

batzen
- 161
- 2
- 4