简体   繁体   中英

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

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

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.

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.

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. You can simply listen for the event in the popup window and update the gui that way. Just remember to check the dispatcher to ensure its safe to update the gui.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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