简短回答:尝试在不指定上下文null
参数的情况下显示对话框 -通过利用C# 4.0中引入的可选参数将其保留为默认值:
this.windowManager.ShowDialog(MyViewModel, settings: settings);
长答案:这是方法WindowManager.ShowDialog()的样子:
/// <summary>
/// Shows a modal dialog for the specified model.
/// </summary>
/// <param name="rootModel">The root model.</param>
/// <param name="context">The context.</param>
/// <param name="settings">The optional dialog settings.</param>
public virtual void ShowDialog(object rootModel,
object context = null,
IDictionary<string, object> settings = null)
{
var view = EnsureWindow(rootModel,
ViewLocator.LocateForModel(rootModel, null, context));
ViewModelBinder.Bind(rootModel, view, context);
var haveDisplayName = rootModel as IHaveDisplayName;
if(haveDisplayName != null &&
!ConventionManager.HasBinding(view, ChildWindow.TitleProperty))
{
var binding = new Binding("DisplayName") { Mode = BindingMode.TwoWay };
view.SetBinding(ChildWindow.TitleProperty, binding);
}
ApplySettings(view, settings);
new WindowConductor(rootModel, view);
view.Show();
}
Notice that it call EnsureWindow()
and pass context argument into. If you specify this argument as string.Empty (or "") it will be treated further in Caliburn implementation differently then just null
value to find corresponding View for provided view-model.
Hope this help.