无法找到视图模型的视图?

发布于 2024-12-01 14:21:09 字数 553 浏览 8 评论 0原文

我正在尝试为一个小型网站制作一个组合用户界面。

我的建筑树如下所示:

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

最后一个属于 IPodConductor,因此包含 IPage(如 MainPage、ContactPage ..)的 Screen(pagepod)的组合

我的整个构造可以找到遵循 Caliburns 约定的所有视图模型和视图,但不能找到我的 MainPage。

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

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

按照惯例,Caliburn 应该能够找到我的视图...但事实并非如此。

任何人都可以提供有关找出或调试此错误的提示的任何提示。

提前致谢。

I'm trying to make a composition UI for a small website.

My building tree looks like this:

  • Shell (Conductor.Collection.AllActive)
    • Contains multiple IPod's (you can view them as small widgets)
    • 1 Pod is a PagePod.

This last one is of sort IPodConductor, so a combination of a Screen ( the pagepod ) containing IPage (like MainPage, ContactPage .. )

My whole construction can find all my viewmodels and views following Caliburns convention, but not my MainPage.

The error is as following:
"Cannot find view for Gymsport.Client.Pages.Main.MainPageViewModel"

My structure to the view is as following:
Gymsport.Client.Pages.Main.MainPageView

Following the convention, caliburn should be able to locate my view... but it doens't.

Anybody any tips on to figure out or pointers for debugging this error.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半世蒼涼 2024-12-08 14:21:09

在 CM 中,还有其他逻辑用于查找有关页面等单词的视图(请参阅 此处)。

因此,您可以更改视图以匹配 CM 中的规则,从视图模型中删除“Page”一词,或者您可以使用类似以下内容强制执行自定义简单视图位置:

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;
};

In C.M, there is additional logic for finding Views concerning words like Page, etc. (see here).

So you can either change your views to match the rules in C.M, remove word Page from your view models, or you can enforce custom simple view location with something like that:

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;
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文