2016-05-26 17 views
1

私はあなたの助けが必要です。私はすでに、MVVM Light for WPFを使ってダイアログを表示する方法について正しい方法を研究しました。しかし、私は不運です。MVVM Light for WPFを使用してダイアログを表示するにはどうすればいいですか?

DialogServiceを実装/使用する方法については、https://marcominerva.wordpress.com/2014/10/14/dialogservice-in-mvvm-light-v5/を読んで、DialogServiceがないことを確認してください。私はWPFのDialogServiceを実装する必要があります。

誰かがDialogService for WPFを実装する方法を教えてくれますか?あなたの助けが高く評価されます。

+0

私はこのトピックについて昨年書いた[この記事](http://www.codeproject.com/Articles/820324/Implementing-Dialog-Boxes-in-MVVM)を見てください。これは実装方法を示していますそれらは、通常のウィンドウの管理方法に近いものです。また、プロジェクトに直接追加できるスタンドアロンの完全なライブラリを提供します。 –

+0

ありがとうございました!私はこの記事を読んだことがありますが、このアプローチではダイアログボックスのプロパティを作成して表示プロパティで宣言する必要があります。私はまだ答えを探しています。 – Patrick

答えて

1

これが完璧な解決策であるかどうかはわかりませんが、私はダイアログを表示するサービスを作成しました。

public interface IDialogService { 
    void ShowError(Exception Error, string Title); 
    void ShowError(string Message, string Title); 
    void ShowInfo(string Message, string Title); 
    void ShowMessage(string Message, string Title); 
    bool ShowQuestion(string Message, string Title); 
    void ShowWarning(string Message, string Title); 
} 

public class DialogService : IDialogService { 
    public void ShowError(Exception Error, string Title) { 
     MessageBox.Show(Error.ToString(), Title, MessageBoxButton.OK, MessageBoxImage.Error); 
    } 

    public void ShowError(string Message, string Title) { 
     MessageBox.Show(Message, Title, MessageBoxButton.OK, MessageBoxImage.Error); 
    } 

    public void ShowInfo(string Message, string Title) { 
     MessageBox.Show(Message, Title, MessageBoxButton.OK, MessageBoxImage.Information); 
    } 

    public void ShowMessage(string Message, string Title) { 
     MessageBox.Show(Message, Title, MessageBoxButton.OK); 
    } 

    public bool ShowQuestion(string Message, string Title) { 
     return MessageBox.Show(Message, Title, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes; 
    } 

    public void ShowWarning(string Message, string Title) { 
     MessageBox.Show(Message, Title, MessageBoxButton.OK, MessageBoxImage.Warning); 
    } 
} 

これは私とうまく動作します。プラットフォーム上で変更する必要がある場合は、DialogServiceクラスを変更するだけです。

関連する問題