Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implement Mahapps MessageBox with OK and Cancel

I am trying to implement Mahapps Metro Message box in 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.

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.

like image 925
mukul nagpal Avatar asked Dec 03 '25 16:12

mukul nagpal


1 Answers

Since the ShowMessageAsync method is an extension method of the MetroWindow class, you need to have a window to be able to call it.

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:

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

Can't use await on ShowMessageAsync

like image 105
mm8 Avatar answered Dec 06 '25 05:12

mm8