我不确定您是否仍在寻求任何帮助,但我在对话框方面采取的方法是让视图模型引发视图可以处理的事件。视图现在可以做任何它想要将数据获取到视图模型的操作,因此您可以毫无问题地在视图中显示对话框。您将对话框中的响应传递给事件的 EventArgs,以便视图模型拥有它正在寻找的数据以便继续。
例如:
Public Class View
Private WithEvents _VM AS new ViewModel()
Private Sub _VM_AddingItem(Sender AS Object, E AS ViewModel.ItemEventArgs)
Dim Dialog As new SomeDialog()
If Dialog.ShowDialog then
E.Item = Dialog.Item
Else
E.Cancel = True
End If
End Sub
End Class
Public Class ViewModel
Public Sub AddItem(Item AS Object)
Do Some Work here
End Sub
Private Sub _AddItem()
Dim Args AS New ItemEventArgs()
OnAddingItem(Args)
If not Args.Cancel Then AddItem(Args.Item)
End Sub
Protected Sub OnAddingItem()
RaiseEvent AddingItem(me, ItemEventArgs)
End Sub
Public Event AddingItem(Sender AS Object, E As ItemEventArgs)
Public Class ItemEventArgs
Public Property Item AS Object
Public Property Cancel AS Boolean = false
End Class
End Class
然后只需将您的命令连接到_AddItem
仅引发事件以收集该方法所需数据的私有AddItem
方法。我希望这有帮助 :)