これが完璧な解決策であるかどうかはわかりませんが、私はダイアログを表示するサービスを作成しました。
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クラスを変更するだけです。
私はこのトピックについて昨年書いた[この記事](http://www.codeproject.com/Articles/820324/Implementing-Dialog-Boxes-in-MVVM)を見てください。これは実装方法を示していますそれらは、通常のウィンドウの管理方法に近いものです。また、プロジェクトに直接追加できるスタンドアロンの完全なライブラリを提供します。 –
ありがとうございました!私はこの記事を読んだことがありますが、このアプローチではダイアログボックスのプロパティを作成して表示プロパティで宣言する必要があります。私はまだ答えを探しています。 – Patrick