开发者

Unable to find view for viewmodel?

开发者 https://www.devze.com 2023-03-31 08:22 出处:网络
I\'m trying to make a composition UI for a small website. My building tree looks like this: Shell (Conductor.Collection.AllActive)

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.


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

精彩评论

暂无评论...
验证码 换一张
取 消