如何隐藏“父母”带有“child”的窗口/线程窗口/线程 [英] How can I hide "parent" window/thread with "child" window/thread

查看:122
本文介绍了如何隐藏“父母”带有“child”的窗口/线程窗口/线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



假设我们有一个主题:

Hello,

Let's say we have a Thread :

Thread mainWindow = new Thread(new ThreadStart(StartMainWindow));



从MainWindow开始:


Wich start MainWindow :

private void StartMainWindow()
        {
            MainWindow main = new MainWindow();
            main.Show();            
        }





如何在经过一些治疗后隐藏第二个窗口



想法是隐藏第二个窗口并在治疗结束时交换它们



我尝试过:



也许我只会使用一个窗口,但我想知道这是否可能



How can I hide the first window from the second after some treatments

The idea is to hide the second window and swap them at the end of treatment

What I have tried:

Maybe I will use only one window but I want to know if this is possible

推荐答案

您好!



我记得WPF Dispatcher线程是主线程,它处理所有UI控件。因此,如果您要渲染或控制任何UI组件;你必须使用Dispatcher线程。



现在回到你的问题。据我所知,你有2个窗口,你想用另一个窗口隐藏主窗口。换句话说,您实际上正在更改主窗口。

这可以通过获取Current App调度程序线程并设置当前窗口来实现。

例如



Hello!

As I remember WPF Dispatcher thread is main thread, whose handling all UI control. So if you are going to render or control any UI component; you have to use Dispatcher thread.

Now came back to your question. As I understand, you have 2 windows, and you want to hide the main window with another one. In other words, you are actually changing main window.
This can be achieved by getting Current App dispatcher thread, and set current window.
e.g.

Application.Current.Dispatcher.Invoke((Action)delegate
{
   SecondWindow window = new SecondWindow ();
   App.Current.MainWindow.Close();
   App.Current.MainWindow = window;
   App.Current.MainWindow.Show();
});





请注意我正在使用



Note that I am Using

Application.Current.Dispatcher.Invoke

因为我从辅助线程调用(使用Task)。否则,您不能使用辅助线程

because I am invoking from secondary thread (using Task). Otherwise you are not allowed to play with UI controls from secondary thread


这篇关于如何隐藏“父母”带有“child”的窗口/线程窗口/线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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