In UserControl,I can not use the method ShowMessageAsync().What can I do to use it.
Asked
Active
Viewed 1,542 times
1 Answers
1
You need to get a reference to the parent MetroWindow
. You could do this using the Window.GetWindow
method:
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
this.Loaded += UserControl1_Loaded;
}
private async void UserControl1_Loaded(object sender, RoutedEventArgs e)
{
Metro.Controls.MetroWindow window = Window.GetWindow(this) as Metro.Controls.MetroWindow;
if(window != null)
{
await window.ShowMessageAsync("This is the title", "Some message");
}
}
}
You always need a reference to a MetroWindow
to be able to show a dialog using the ShowMessageAsync
method in MahApps.Metro
.

mm8
- 163,881
- 10
- 57
- 88
-
Please remember to accept the answer: https://meta.stackexchange.com/questions/23138/how-to-accept-the-answer-on-stack-overflow – mm8 Mar 28 '17 at 08:53