mukul nagpal
mukul nagpal

Reputation: 103

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.

Upvotes: 3

Views: 8806

Answers (1)

mm8
mm8

Reputation: 169270

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

Upvotes: 3

Related Questions