silverlight - 找不到 View 模型的 View ?

标签 silverlight mvvm caliburn.micro convention

我正在尝试为小型网站制作组合 UI。

我的建筑树是这样的:

  • 外壳 (Conductor.Collection.AllActive)
    • 包含多个 iPod(您可以将它们视为小部件)
    • 1 个 Pod 是一个 PagePod。

最后一个是 IPodConductor,因此是包含 IPage(如 MainPage、ContactPage ..)的屏幕(pagepod)的组合

我的整个构造可以按照 Caliburns 约定找到我所有的 View 模型和 View ,但不能找到我的 MainPage。

错误如下: “找不到 Gymsport.Client.Pages.Main.MainPageViewModel 的 View ”

我的 View 结构如下: Gymsport.Client.Pages.Main.MainPageView

按照约定,caliburn 应该能够找到我的 View ......但它没有。

任何人任何关于找出或调试此错误的提示。

提前致谢。

最佳答案

在 C.M 中,有额外的逻辑来查找有关页面等单词的 View (参见 here )。

因此,您可以更改 View 以匹配 C.M 中的规则,从 View 模型中删除单词 Page,或者您可以使用类似的东西强制自定义简单 View 位置:

ViewLocator.LocateTypeForModelType = (modelType, displayLocation, context) =>
{
    var viewTypeName = modelType.FullName.Substring(
        0,
        modelType.FullName.IndexOf("`") < 0
            ? modelType.FullName.Length
            : modelType.FullName.IndexOf("`")
        );

    viewTypeName = viewTypeName.Replace("Model", string.Empty);

    if (context != null)
    {
        viewTypeName = Regex.Replace(viewTypeName, "View$", string.Empty);
        viewTypeName += "." + context;
    }

    var viewType = (from assembly in AssemblySource.Instance
                    from type in assembly.GetExportedTypes()
                    where type.FullName == viewTypeName
                    select type).FirstOrDefault();

    return viewType;
};

关于silverlight - 找不到 View 模型的 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7196554/

相关文章:

c# - 如何从 Deployment.Current.Dispatcher.BeginInvoke 获取结果?

.net - 我应该使用哪些资源将我的 .NET 应用程序移植到 Mono 或 Moonlight?

wpf - 如何在 View 模型中使用第三方控件?

c# - 使用 MVVM,如何在低级别服务和 View 模型之间建立通信线路?

c# - 带有 Caliburn Micro wpf 的多个模板 TreeView

caliburn.micro - BindableCollection<> AddRange 慢

c# - 将特定于 Silverlight 的 System.Xml.Linq dll 与非 Silverlight System.Xml.Linq dll 混合

c# - WPF-MVVM : ComboBox value after SelectionChanged

java - 单例与依赖注入(inject)

c# - 为Caliburn.Micro Action Message指定自定义防护属性