开发者

WPF How to get window reference that is loaded from a page that is into it?

I have a page that is into a window similiar to MDI. I want to get the reference of the window in what the 开发者_如何转开发page is placed into. The window is loaded.

Thanks.


I'm not 100% sure if I am understanding exactly what you mean.... if you're talking about a Windows Application that where a User Control is situated in a Window, and you want to do something to the Window from the User Control, you can simply do this (in this example it just closes the Window):

Window window = Window.GetWindow(this);
if (window != null) 
    window.Close();

If this isn't what you meant, could you please post a bit more detail.


I ran into a similar problem and I started with Richard's solution (+1 vote from me!), but I found I had to cast the type to my specific window type to do anything useful.

MainWindow w = (MainWindow)Window.GetWindow(this);
w.method_to_run();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜