0

In a wpf/mvvm/prism application, I got a problem when I navigate from a view to another.

I put a breakpoint in the navigation function prepare/request, in the AViewModel:

    private void Model(object sender)
    {
        if (sender == null) return;
        var file = ((RawImage)sender).FullName;
        var navParams = new NavigationParameters { { "filein", file } };
        var uri = new Uri(typeof(BView).Name + navParams, UriKind.Relative);
        _regionManager.RequestNavigate(RegionNames.TabRegion, uri, nr =>
        {
            var error = nr.Error;
            var result = nr.Result;
        }); //breakpoint here
    }

ne.Error: Cannot create navigation target 'BView'

In the module , I have registered the types:

    protected override void RegisterTypes()
    {
        Container.RegisterTypeForNavigation<AView>();
        Container.RegisterType<IAViewModel, AViewModel>();
        Container.RegisterTypeForNavigation<BView>();
        Container.RegisterType<IBViewModel, BViewModel>();
        Container.RegisterTypeForNavigation<CView>();
        Container.RegisterType<ICViewModel, CViewModel>();
    }

When I ask to navigate to CView, it works but not BView. Each view has its interface and viewmodel in its own folder.

What might be the problem ? Cheers

1 Answer 1

0

I was able to investigate more and do a view injection from InitializeModule() (of the module):

        var region = RegionManager.Regions[RegionNames.TabRegion];
        var view = Container.Resolve<BView>();
        region.Add(view);
        region.Activate(view);

Which led to a more readable message:

Exception thrown: 'Microsoft.Practices.Unity.ResolutionFailedException' in Microsoft.Practices.Unity.dll

Additional information: Resolution of the dependency failed, type = "Some.Namespace.BView", name = "(none)".

Exception occurred while: while resolving.

Exception is: InvalidOperationException - The type BViewModel has multiple constructors of length 1. Unable to disambiguate.

And by making sure I have only one viewmodel constructor with one argument:

    public BViewModel(IRegionManager regionManager)
    {
        _regionManager = regionManager;
        Initialize();
    }

I was finally able to go further.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.