简体   繁体   English

在每个窗口中使用一个弹出控件在WPF中显示进度消息

[英]using one popup control for every window to show progress message in WPF

I have around 15 windows in my WPF application, and each window call a one class for operation 我的WPF应用程序中大约有15个窗口,每个窗口都调用一个类进行操作

eg:Load, Delete, etc. and I don't want to add popup control in every window. 例如:加载,删除等,并且我不想在每个窗口中添加弹出控件。 Every operation 每次操作

method in operation class takes Window as a parameter, is there any way that I can show 操作类中的方法将Window作为参数,有什么方法可以显示

operation progress message popup at this window from operation method? 操作方法在该窗口弹出操作进度信息?

or any other better approach to show progress message also while showing progress message the 或其他任何更好的方法来显示进度消息,同时显示进度消息

window should be get disabled to stop user making any other operation. 应该禁用该窗口以停止用户进行任何其他操作。

Thanks 谢谢

From what you say, your status window is a modal window. 用您所说的,您的状态窗口是模式窗口。 If you get all your operation class to implement the same interface for reporting progress (and also inform on what is beeing done, i guess), you could make one only status window that you instanciate with the operation being done, and that you would call with ShowDialog. 如果让所有操作类都实现用于报告进度的相同接口(我想还可以告知正在完成的操作),则可以创建一个唯一的状态窗口,以实例化该操作的完成状态,并调用与ShowDialog。

I would make a static class that manages status messages and have the main window listen for when those messages come in. That way only the main window is responsible for showing a popup, and all of the other windows go to one place to report status updates. 我将创建一个静态类来管理状态消息,并让主窗口在这些消息进入时进行监听。这样,只有主窗口负责显示弹出窗口,而所有其他窗口都转到一个位置以报告状态更新。

Pseudo: 伪:

static class StatusManager
{
    delegate onMessageReceivedEvent(string message);
    static event onMessageReceivedEvent OnMessageReceived;

    static void PostMessage(string message)
    {
        if(OnMessageReceived != null)
             OnMessageReceived.Invoke();
    }
}

In your main window, just += OnMessageReceived and post the message on event. 在主窗口中,只需+ = OnMessageReceived并在事件后发布消息。

Also, if you just want a status message to stay up until all others are done, keep a counter of running windows and once it reaches 0, close the popup. 另外,如果您只希望状态消息一直保持到所有其他操作都完成,请保留运行窗口的计数器,并在窗口达到0时关闭弹出窗口。 You can simply listen for the event in the popup window and update the gui that way. 您可以简单地在弹出窗口中监听事件并以这种方式更新gui。 Just remember to check the dispatcher to ensure its safe to update the gui. 只要记住检查调度程序以确保其安全即可更新gui。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM