2016-09-03 7 views
0

GalaSoft.MvvmLight 어셈블리에 정의 된 IDialogService를 구현하는 데 어려움을 겪고 있습니다. 당신은 정말IDialogService 구현 방법

public Task ShowError(Exception error, string title, string buttonText, Action afterHideCallback) 
    { 
     //var result = MessageBox.Show(""); 
     return Dispatcher.Invoke(() => MessageBox.Show("whatever")); 
     //return Dispatcher.BeginInvoke(delegate() { MessageBox.Show("your stuff"); }); 
     //var dg = new Action(() => { MessageBox.Show("", ""); }); 
     //return Dispatcher.CurrentDispatcher.BeginInvoke(dg); 
    }  

어떻게 WPF에 대한 Messagebox.Show이 비동기 방법을 사용할 수 있습니다 같은 첫 번째 방법을 구현하기 위해 애 쓰고 nuget 패키지 MvvmLightLibs

public interface IDialogService 
{ 

    Task ShowError(string message, string title, string buttonText, Action afterHideCallback); 
    Task ShowError(Exception error, string title, string buttonText, Action afterHideCallback); 
    Task ShowMessage(string message, string title); 
    Task ShowMessage(string message, string title, string buttonText, Action afterHideCallback); 
    Task<bool> ShowMessage(string message, string title, string buttonConfirmText, string buttonCancelText, Action<bool> afterHideCallback); 
    Task ShowMessageBox(string message, string title); 
} 

으로부터받을 수 있나요? 도와주세요.

나는 어떤 작품을 보려고하지만, 지금까지는 행운이 없습니다. 누군가 나를 도울 수 있습니까?

+0

사용의

public async Task ShowError(Exception error, string title, string buttonText, Action afterHideCallback) { await Dispatcher.InvokeAsync(() => MessageBox.Show("whatever")); Console.WriteLine("awaited Box closed"); } 

예 ShowError를 비동기 메소드로 구현하고 싶습니까? – Joe

+0

예, 비동기 메서드의 메시지 보 – VivekDev

답변

3

당신은 당신이 당신의 showError는 비동기가 될 싶은 말은하지만 실제로 async 키워드로 방법을 표시하지 않으며 아무것도 기다리고 않습니다

private async void Button_Click(object sender, RoutedEventArgs e) 
    { 
     await ShowError(new Exception("Test"), "test", "um", null); 
     Console.WriteLine("awaited showError"); 
    }