0

私はWPFを初めて使用し、 RelayCommandを使用してデモアプリケーションを実装しようとしました。

私の質問はこれです:

ユーザーに最初に実行したいかどうかを尋ねるコマンドを実行したい場合、それを実行するための最良の方法は何ですか?「よろしいですか?」が必要です。ポップするメッセージボックス。ただし、コマンドはビューモデルで実行されるため、もちろんGUIをいじりたくありません。

ありがとう

4

2 に答える 2

1

私がこれに対処する方法はIDialogService、IOCに登録され、ViewModelで使用できるインターフェイスを用意することです。

次に、サービスは「ユーザー」と対話するさまざまな方法を提供します。したがって、ユーザーがダイアログを受け入れることに基づいてtrueまたはfalseを返すConfirmMessageメソッドを使用できます。

次に、単体テストのIDialogService場合、テスト中にViewModelに既定の応答をフィードできるようにする別の実装を使用できます。

于 2011-02-15T06:27:03.320 に答える
0

I just ran into this myself. I'm using MVVM Light, and I used the Messenger to accomplish this.

I had my ViewModel send a GetConfirmationMessage, which I had registered in the code-behind. Within the handler for GetConfirmationMessage, I popped up the dialog box and got the reuslts. If the user clicked on OK, I then sent a ConfirmationReceived message, which was handled by the ViewModel to do the appropriate updates.

于 2011-02-14T14:01:02.197 に答える