简体   繁体   English

MahApps Metro 主题 - 始终在 WPF 应用程序中的所有其他窗口之前显示对话框窗口

[英]MahApps Metro Theme - Always show dialog windows in front of all other windows in WPF Application

I'm pretty new to WPF and the Metro styling and I ran into the following problem:我对 WPF 和 Metro 样式很陌生,但遇到了以下问题:

I open all my message dialogs from the main window of my application by calling ShowMessageAsync()., even when the actual caller is another window (eg a settings window).我通过调用 ShowMessageAsync() 从我的应用程序的主窗口打开所有消息对话框,即使实际调用者是另一个窗口(例如设置窗口)。 Now when for example this settings window is open and wants to show a message that the settings have been saved, the dialog appears in between the main and the settings window (which makes sense because the main window is the caller and the settings window is a child of that main window).现在,例如,当此设置窗口打开并想要显示设置已保存的消息时,对话框会出现在主窗口和设置窗口之间(这是有道理的,因为主窗口是调用者,设置窗口是该主窗口的子级)。 What I want is for all dialogs created by ShowMessageAsynch() to be displayed always in front of the screen.我想要的是 ShowMessageAsynch() 创建的所有对话框始终显示在屏幕前面。

Any ideas on how to achieve that?关于如何实现这一目标的任何想法?

Thanks in advance for your answers!提前感谢您的回答!

I know this is an older question but I could not find a good answer for this anywhere.我知道这是一个较旧的问题,但我无法在任何地方找到一个好的答案。 I ended up minimizing any child windows, opening the message dialog, and then setting the child windows back to normal.我最终最小化了所有子窗口,打开消息对话框,然后将子窗口设置为正常。 I would still be curious to know if there is a better solution for this problem.我仍然很想知道这个问题是否有更好的解决方案。

    private MetroWindow MetroWindow => (MetroWindow)Application.Current.MainWindow;

    public async Task ShowInfoDialog(string text)
    {
        var childWindows = MetroWindow.OwnedWindows;
        MinimizeChildWindows(childWindows);
        await MetroWindow.ShowMessageAsync("Info", text);
        MaximizeChildWindows(childWindows);
    }

    private void MinimizeChildWindows(WindowCollection childWindows)
    {
        foreach (Window win in childWindows)
        {
            win.WindowState = WindowState.Minimized;
        }
    }

    private void MaximizeChildWindows(WindowCollection childWindows)
    {
        foreach (Window win in childWindows)
        {
            win.WindowState = WindowState.Normal;
        }
    }

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

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