wpf 使用 OK 和 Cancel 实现 Mahapps MessageBox
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41121566/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Implement Mahapps MessageBox with OK and Cancel
提问by mukul nagpal
I am trying to implement Mahapps Metro Message boxin my code, but want to use it on a class, not any WPF Window, can I achieve this ?, because I don't want to use ordinary Message Boxes.
我正在尝试Mahapps Metro Message box在我的代码中实现,但想在一个class而不是任何一个上使用它WPF Window,我能做到吗?,因为我不想使用普通的Message Boxes.
switch(x)
{
case "a":
//Do something
break;
case "b":
var result = MessageBox.Show("TitleMessage","If you want to continue",MessageboxButton.YesNo);
break;
}
so instead of this MessageBox, I want to use Mahapps Message Box, then use this result variable.
所以不是这个MessageBox,我想使用Mahapps Message Box,然后使用这个结果变量。
回答by mm8
Since the ShowMessageAsync method is an extension method of the MetroWindow class, you need to have a window to be able to call it.
由于 ShowMessageAsync 方法是 MetroWindow 类的扩展方法,因此您需要有一个窗口才能调用它。
If your applications's main window is a metro window you should be able to call the method like this from any class that has a reference to the PresentationFramework assembly:
如果您的应用程序的主窗口是一个 Metro 窗口,您应该能够从任何引用 PresentationFramework 程序集的类中调用这样的方法:
var metroWindow = (Application.Current.MainWindow as MetroWindow);
await metroWindow.ShowMessageAsync("title", "message...");
Please refer to the following links for more information: https://github.com/MahApps/MahApps.Metro/issues/1129
更多信息请参考以下链接:https: //github.com/MahApps/MahApps.Metro/issues/1129

