Prism 4: RequestNavigate() not working

我的未来我决定 提交于 2019-12-03 22:35:22

Finally figured this one out. The answer is in the Developer's Guide to Microsoft Prism (Ver 4), pp. 120-121. It has two parts:

First, the UserControl and RibbonTab objects were resolving from Unity as System.Object types. That's a limitation of Unity and the overload that I used to register the view objects. To get them to resolve to the correct types, you need to use a different overload for IUnityContainer.RegisterType():

// Register other view objects with DI Container (Unity)
m_Container.RegisterType<Object, ModuleAView>("ModuleAView");
m_Container.RegisterType<Object, ModuleARibbonTab>("ModuleARibbonTab");

This overload maps Unity's native System.Object resolution to the correct type for the view requested. See the note on p. 120 of the Developer's Guide.

The second problem wasn't explicitly stated in my question, but it occured when I fixed the first problem. I wanted each module's RibbonTab to be removed when I switched to the other module. Since my Ribbon Region acts like an ItemsControl, both RibbonTabs ended up being shown--Module A's RibbonTab wasn't unloaded when I switched to Module B. To solve that problem, I implemented IRegionMemberLifetime on the RibbonTab classes. That issue is covered on p. 121 of the Developer's Guide.

BTW, I implemented the IRegionMemberLifetime interface on the View objects, rather than their View Models, because the interface does not impact the back end of the app, only the view object.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!