0

问题是,当我使用 windowManager.showDialog() 函数的第三个参数(即设置)时,我收到错误消息,即未找到我的 ViewModel 的视图。

var view = Caliburn.Micro.ViewLocator.LocateForModel(MyViewModel, null, null);
dynamic settings = new System.Dynamic.ExpandoObject();
settings.ShowInTaskbar = false;
Caliburn.Micro.ViewModelBinder.Bind(MyViewModel, view, null);
this.windowManager.ShowDialog(MyViewModel, "", settings);

看起来像提供设置,视图不见了。但是当我删除最后两个参数时,事情工作文件。我尝试过 SO 和其他论坛,但找不到答案。

提前感谢您的支持。伊尔凡

4

1 回答 1

2

简短回答:尝试在不指定上下文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.

于 2013-07-23T22:57:03.870 回答