开发者

WPF: Is there a way to directly get the Window object a control is on?

Is there a way to directly get the Window object a control is on?开发者_开发技巧


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.


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:

stackoverflow: get active window(s) in wpf


A bit late, but the following works pretty fine for me.

var ownerWindow = Window.GetWindow(yourControl);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜