如何让 MessageBox.Show() 在我的 WPF 应用程序中间弹出?
问题描述:
我有一个 700w x 300h WPF 应用程序,可以将它拖动到大屏幕上的任何位置.
I have a 700w x 300h WPF applciation and can drag it anywhere on my large screen.
当我的应用程序执行时:
When my application executes:
MessageBox.Show("Sorry, this function is not yet implemented.");
消息框出现在我的屏幕中间,它可能靠近也可能不靠近应用程序本身.
the mesage box appears in the middle of my screen, which may or may not even be near the application itself.
如何让我的 MessageBox 出现在我的应用程序中间?
How can I get my MessageBox to appear in the middle of my application instead?
答
如果您的应用有多个窗口,您可能需要使用 Application.Current.MainWindow
:
If your app has several windows, you might want to use Application.Current.MainWindow
:
MessageBox.Show(Application.Current.MainWindow, "Can't login with given names.", "Login Failure", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.Cancel);