打开一秒后怎么回到窗口? [英] How do I return to a window after opening a second?

查看:139
本文介绍了打开一秒后怎么回到窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序具有这样的性质,我需要连续地跳过许多窗口。从我的菜单窗口我需要打开另一个窗口(从选择),禁用或关闭菜单窗口。

My application is of such a nature that I need to jump around many windows consecutively. From my menu window I need to open another window (from the selection) and the disable or close the menu window.

我正在使用的是window.show和那么这个.lose()方法来关闭菜单窗口。

What I'm currently using is window.show and then this.close() method to close the menu window.

Ex:

    private void MainMenuControl_Link1MouseDown(object sender, RoutedEventArgs e)
    {

        // Utilities
        UtilitiesMenyWindow UtilitiesMenyWindow = new UtilitiesMenyWindow(); // Assign Variable to window
        UtilitiesMenyWindow.Show(); // Open window
        this.Close(); // close current window

    }

然后从新窗口中只需使用相同的方法重新打开MainMenu窗口。

Then from within the new windows I just reopen the MainMenu window using the same method.

    private void Utilities_Link3MouseDown(object sender, RoutedEventArgs e)
    {
        // Return to Main
        MainMenuWindow MainMenu = new MainMenuWindow(); // Assign Variable to window
        MainMenu.Show(); // Open Main window
        this.Close(); // close login window
    }

然后我还保留一个带有静态变量的公共变量类将所有窗口中的所有变量存储为通用。

I then also keep a public variable class with static variables to store all the variables that are generic to all the windows.

除了一个标签之外,所有这些都对我有效。如果我从另一个窗口(而不是MainWindow)调用UtilitiesMenyWindow,它将返回到MainMenu,而不是从我打开它的窗口。

All this is working fine for me except for one snag. If I were to call the UtilitiesMenyWindow from another window (not MainWindow) it's going to return to the MainMenu instead of the window I opened it from.

是否更容易通常的方式返回到打开辅助窗口的窗口,而不必告诉它关闭自己并打开一个特定的窗口(在这种情况下,它是Maincape的硬编码)(显然我首先打开然后关闭)

Is there a easier more generic way to return to the window that opened the secondary window without having to tell it to close itself and open a specific window (in this case it's "hardcoded" to MainMenu) (Obviously I first open and then close)

我正在看Unloaded事件,但是如何让原始窗口保持隐藏,直到这个事件发生,而不必坐在那里等待循环,这不是一个好主意。
也许有人可以指导我以一种自动事件的方式将其设置为触发事件处理程序,然后再激活以前的窗口?

I was looking at the Unloaded event but how do I get the original window to stay hidden until this event occurs without it having to sit there and wait in a loop which is not a good idea. Maybe somebody can guide me in a way to set it up as an automatic event that "fires" the event-handler, which in turn then activates the previous window?

推荐答案

您可以关闭原始窗口 - 由于所有窗口都可能继承自Window类,因此您只需将当前窗口存储在实用程序菜单中的Window类型变量中

You could just close the original window - since all your windows are probably inheriting from Window class you just need to store the current window in a 'Window' typed variable on the utilities menu

这样你可以继续做你正在做的事情:

This way you can continue doing what you are doing:

eg

private void MainMenuControl_Link1MouseDown(object sender, RoutedEventArgs e) 
{ 

    // Utilities 
    UtilitiesMenyWindow UtilitiesMenyWindow = new UtilitiesMenyWindow(); // Assign Variable to window 
    UtilitiesMenyWindow.ReturnWindow = this;
    UtilitiesMenyWindow.Show(); // Open window 
    this.Hide(); // hide current window 

} 

并添加

Window _returnWindow;

在您的实用程序窗口类上

on your utility window class

然后在该类关闭方法中,您可以调用原始窗口类型:

Then in that class on the close method you can call the original window type:

private void Utilities_Link3MouseDown(object sender, RoutedEventArgs e)
{
    // Return to original
    _returnWindow.Show();
    this.Close(); // close login window
}

这当然是假设你不要杀死原始窗口

This is of course assuming you don't kill the original window

这篇关于打开一秒后怎么回到窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆