2
Vote

[MEF] Navigation to an existing View

description

When I try to navigate to an existing View, if the view was exported in MEF using a contract name different from its type name, the navigation won't complete successfully and a "ViewAlreadyExistsInRegion" exception is raised.
 
From my analysis this can be fixed adding an override of the GetCandidatesFromRegion method in the class MefRegionNavigationContentLoader, in order to examine not only the Type name but also the ContractName from the Export attribute.
 
Attached you may find my proposed override.

file attachments

comments

aadami wrote Jun 8, 2012 at 6:00 PM

Hi,

We will examine your proposed code changes.

Thanks for sharing your findings with the rest of the community, as it might be useful for other users pursuing this scenario.

Additionally, for those interested in this subject you could find the following blog post useful, where this problem is explained in further detail:

Matching contract names and view names in Prism region navigation http://blogs.southworks.net/aadami/2011/10/14/matching-contract-names-and-view-names-in-prism-region-navigation/

http://blogs.southworks.net/aadami/2011/10/14/matching-contract-names-and-view-names-in-prism-region-navigation/

Thanks,

Agustin Adami
http://blogs.southworks.net/aadami

aadami wrote Jun 27, 2012 at 7:14 PM

Hi,

We could verify your proposed workaround for this issue, and we believe it's a great approach to avoid this undesired behavior.

Also, as this error also appears when using Unity as the container, we implemented a similar workaround for it, based on your idea. For those interested you can find it in the following related work item:

Prism ContentControl Region RequestNavigate - "View already exists in region"

http://compositewpf.codeplex.com/workitem/8121

We are leaving this work item open so that the team consider it, for future releases.

Thanks again,

Agustin Adami
http://blogs.southworks.net/aadami