Edit prism framework rules

voidstreamvoidstream FRMember ✭✭✭


In my application i start on a connection page.
A user can be Manager, Admin, SimpleUser etc...
Foreach type of user i don't have the same menu, the same pages so my solution look like the attach file

I use prims and my solution look the attach file.
When i create a PrismContentPage in the UserManager folder the ViewModels is create in ViewModels/ whereas i need he will go in ViewModels/UserManager.
How i can edit Prism rules?

Best regards

Best Answer


  • BrianLagunasBrianLagunas USInsider ✭✭✭
    edited December 2016

    FYI, you can change the convention for the ViewModelLocator. Read the section titled "Change those nasty conventions" in this post: http://brianlagunas.com/getting-started-prisms-new-viewmodellocator/

    Having said that, I would recommend the approach you are taking now by explicitly registering the VM with the View. This is actually better performing since you do not have to use reflection to discover the VMs.

  • LeandroMirandaLeandroMiranda USMember

    @BrianLagunas , I found at your blog the post about Change nasty conventions, and the example was made for WPF applications. In PrismApplication class there are no OnStartup method. I try put the snippet in the constructor and OnInitialized, but with no success. Using ConfigureViewModelLocator it's OK and I can use subfolders in Views folder to organize my classes, but in the default convention using the View/ViewModels folders, it's possible to use subfolders?

  • BrianLagunasBrianLagunas USInsider ✭✭✭

    @LeandroMiranda of course. You can change the conventions to be whatever you want. Just override the ConfigureViewModelLocator method, and setup your own conventions. Or just use the RegisterTypeForNavigation<View, ViewModel method and don't worry about using conventions at all.

  • NMackayNMackay GBInsider, University mod
    edited April 2017


    I have my view's in a sub folder hierarchy (phone,Tablet,Shared etc), I looked at changing the convention but I used up going with Brian's second suggestion when instantiating my modules. Also it's a little quicker too.

  • LeandroMirandaLeandroMiranda USMember
    edited April 2017

    That's cool @BrianLagunas and @NMackay. It's really a little quicker. It wouldn't must be the default behavior in Prism extension for VS instead register RegisterTypeForNavigation TView and use reflection to discover the ViewModel?

  • NMackayNMackay GBInsider, University mod


    I guess it's easier to get started with autoviewmodel discovery :smile:

  • NathanNunesNathanNunes USMember ✭✭
    edited October 2017

    @BrianLagunas is it possible to refer to Viewmodels which are in a separate portable class library and Views are in a different portable class library?

    I have overridden ConfigureViewModelLocator, like this:

    `protected override void ConfigureViewModelLocator()

            ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver((viewType) =>
                var viewName = viewType.FullName;
                var viewAssemblyName = viewType.GetTypeInfo().Assembly.FullName;
                var viewModelName = String.Format(CultureInfo.InvariantCulture, "{0}ViewModel, {1}", viewName, viewAssemblyName);
                return Type.GetType(viewModelName);

    How do I refer to the assembly where my viewmodels are located?

Sign In or Register to comment.