2017-03-27 78 views

回答

1

您需要获得对父MetroWindow的引用。你可以这样做使用Window.GetWindow方法:

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"); 
     } 
    } 
} 

你总是需要一个MetroWindow一个参考,以便能够使用ShowMessageAsync方法MahApps.Metro显示一个对话框。

+0

非常感谢,工作! – a516117636

+0

请记住接受答案:https://meta.stackexchange.com/questions/23138/how-to-accept-the-answer-on-stack-overflow – mm8