I am using MahApps.metro WPF library with MVVM. I have a ViewModel from which I need to display a Dialog. The MetroWindow has ShowMessageAsync. But what is the proper way to access it from the ViewModel? As I understand I need a View instance but passing that into the ViewModel doesn't seem like a good approach.
Best How To :
Use following approach:
ShowMessageAsync in your
ViewModel which you are binding with window.
Now create a behaviour for Window and use following code in behaviour
protected override void OnAttached()
this.AssociatedObject.Loaded += AssociatedObject_Loaded;
void AssociatedObject_Loaded(object sender, RoutedEventArgs e)
if (this.AssociatedObject.DataContext is WindowViewModel)
WindowViewModel vm = this.AssociatedObject.DataContext as WindowViewModel;
vm.ShowMessageAsync = OnShowMessageAsync;
private void OnShowMessageAsync(T param)
//Write your logic to call ShowMessageAsync method.
Now in this way, from the
ViewModel of your
MainWindow you will have ability to open another child window.