2017-03-27 75 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