1
votes

I am new to WPF and Prism, but I already learned that you have to register a View in Unity as an object:

Container.RegisterType<Object,MyView>("My.Assembly.MyView");

Still, when I use

var RelativeUriToMyView = new Uri("My.Assembly.MyView",UriKind.Relative);    
RegionManager.RequestNavigate(RelativeUriToMyView, RegionName, CallbackResult);

the MyView displays as System.Object, and the CallbackResult contains no Error.

What am I missing? I'm happy to provide more information if needed.

2

2 Answers

2
votes

You would want to look at the RegionNavigationContentLoader.cs in the PRISM source code; Here is the code that is loading the view for you.

    protected virtual object CreateNewRegionItem(string candidateTargetContract)
    {
        object newRegionItem;

        try
        {
            newRegionItem = this.serviceLocator.GetInstance<object>(candidateTargetContract);
        }
        catch (ActivationException e)
        {
            throw new InvalidOperationException(
                string.Format(CultureInfo.CurrentCulture, Resources.CannotCreateNavigationTarget, candidateTargetContract),
                e);
        }
        return newRegionItem;
    }

There are several helper methods that take the URI, extract the query string, and create the 'name' used to lookup your view and cast it as an object.

Essentially, the name you are using to associate your concrete class as an object with Unity is the same one you'll need to use when you try to resolve the object with Unity. Here is some pesudocode to explain,

Container.RegisterType<object, ConcreteClass>(typeof(ConcreteClass).FullName);

Locator.GetInstance<object>(UriWithFullName)

If none of this helps, post the RelativeUriToMyView so I can see the contents. Good luck.

1
votes

The issue seemed to be caused by registering the view with its FullName (My.Assembly.MyView) instead of its Name (MyView).

Edit: Changed the question to more accurately reflect the issue.