棱镜4:RequestNavigate()不工作 [英] Prism 4: RequestNavigate() not working

查看:778
本文介绍了棱镜4:RequestNavigate()不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个演示程序来学习棱镜4.应用程序的导航功能有两个模块 - 每一个有三种意见:




  • 用文本块(欢迎来到模块A),一个用户控件

  • 系统RibbonTab(使用区域转接器),和

  • 一个Outlook风格的任务按钮(如Outlook的邮件,日历等)



壳牌有三个命名的区域:RibbonRegion TaskButtonRegion和WorkspaceRegion。视图加载到这些地区。要测试基本设置,我注册的所有三个视图与棱镜大区经理,使他们在启动时加载,和所有工作正常。



接下来,我修改设置使得只有任务键会在启动时加载。其他意见将只装载要求,通过点击任务按钮。我的模块初始化是这样的:

 公共无效初始化()
{
/ *我们注册与棱镜任务按钮区域任务按钮,因为我们希望它
*将立即显示在模块加载,并为
*应用程序的生命周期。 * /

//注册任务按键采用棱镜地区
m_RegionManager.RegisterViewWithRegion(TaskButtonRegion的typeof(ModuleATaskButton));因为我们不想让他们
*实例化,直到我们导航到该模块

/ *我们注册统一的容器这些对象。 * /

//注册查看和碳带标签与容器团结
m_Container.RegisterType单身(typeof运算(ModuleAView),ModuleAView,新ContainerControlledLifetimeManager());
m_Container.RegisterType(typeof运算(ModuleARibbonTab),ModuleARibbonTab,新ContainerControlledLifetimeManager());
}

当用户点击任务按钮,它调用调用一个ICommand对象 IRegionManager.RequestNavigate()来显示的看法:

 公共无效执行(对象参数)
{
//初始化
VAR regionManager = m_ViewModel.RegionManager;

//显示功能区选项卡
变种moduleARibbonTab =新的URI(ModuleARibbonTab,UriKind.Relative);
regionManager.RequestNavigate(RibbonRegion,moduleARibbonTab);

//显示视图
变种moduleAView =新的URI(ModuleAView,UriKind.Relative);
regionManager.RequestNavigate(WorkspaceRegion,moduleAView);
}



该命令被调用点击任务按钮的时候,但我得到是这样的:





在用户控件加载显然作为 System.Object的,我怀疑RibbonTab加载相同。我认为这个问题是我的 RequestNavigate()电话,或我与统一登记。但我不能确定问题所在。



任何人都可以阐明这是怎么回事任何光线?感谢您的帮助。


解决方案

终于想通这一个。答案是的开发人员指南微软棱镜的(版本4),第120-121英寸它有两个部分:



首先,用户控件 RibbonTab 物体从Unity解决为 System.Object的类型。这是团结的限制,并且我用来注册视图对象的过载。为了让他们下定决心,正确的类型,你需要使用 IUnityContainer.RegisterType不同的过载()



<对象,ModuleAView>(ModuleAView)与DI容器(统一)
m_Container.RegisterType< pre> //注册其他视图对象;
m_Container.RegisterType<对象,ModuleARibbonTab>(ModuleARibbonTab);

这超负荷地图团结的原生 System.Object的分辨率为正确的类型要求的视图。请参阅第音符。 120的的开发人员指南



第二个问题是没有明确在我的问题说,但它发生时,我定的第一个问题。我想每个模块的 RibbonTab 当我切换到另一个模块被删除。由于我的丝带地区就像一个的ItemsControl ,无论 RibbonTabs 最终被显示 - 模块A的 RibbonTab 当我切换到模块B.为了解决这个问题并没有卸载,我实现了 IRegionMemberLifetime RibbonTab 类。这个问题是覆盖在页。的的开发人员指南121 的。



BTW,我实现了对视图对象的 IRegionMemberLifetime 接口,而不是他们的视图模型,因为接口不不影响应用程序的后端,只有视图对象。


I am building a demo app to learn the navigation features of Prism 4. The app has two modules--each one has three Views:

  • A UserControl with a text block ("Welcome to Module A")
  • A RibbonTab (using a Region Adapter), and
  • An Outlook-style Task Button (like Outlook's Mail, Calendar, and so on)

The Shell has three named regions: "RibbonRegion", "TaskButtonRegion", and "WorkspaceRegion". The Views load into these regions. To test the basic setup, I registered all three Views with the Prism Region Manager, so that they would load at startup, and all worked as expected.

Next, I modified the setup so that only the Task Buttons would load on startup. Other Views would load only on request, by clicking a Task Button. My module initializers look like this:

public void Initialize()
{
    /* We register the Task Button with the Prism Task Button Region because we want it
     * to be displayed immediately when the module is loaded, and for the lifetime of
     * the application. */

    // Register Task Button with Prism Region
    m_RegionManager.RegisterViewWithRegion("TaskButtonRegion", typeof(ModuleATaskButton));

    /* We register these objects with the Unity container because we don't want them
     * instantiated until we navigate to this module. */ 

    // Register View and Ribbon Tab as singletons with Unity container
    m_Container.RegisterType(typeof(ModuleAView), "ModuleAView", new ContainerControlledLifetimeManager());
    m_Container.RegisterType(typeof(ModuleARibbonTab), "ModuleARibbonTab", new ContainerControlledLifetimeManager());
}

When the user clicks a Task Button, it invokes an ICommand object that calls IRegionManager.RequestNavigate() to show the views:

public void Execute(object parameter)
{
    // Initialize
    var regionManager = m_ViewModel.RegionManager;

    // Show Ribbon Tab
    var moduleARibbonTab = new Uri("ModuleARibbonTab", UriKind.Relative);
    regionManager.RequestNavigate("RibbonRegion", moduleARibbonTab);

    // Show View
    var moduleAView = new Uri("ModuleAView", UriKind.Relative);
    regionManager.RequestNavigate("WorkspaceRegion", moduleAView);
}

The command is being invoked when a Task Button is clicked, but what I get is this:

The UserControl is apparently loading as a System.Object, and I suspect the RibbonTab is loading the same. I think the problem is with my RequestNavigate() call, or my registration with Unity. But I can't identify the problem.

Can anyone shed any light on what's going on? Thanks for your help.

解决方案

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.

这篇关于棱镜4:RequestNavigate()不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆