我在我的 WPF MVVM 应用程序中使用Prism进行导航。我将我的观点登记如下。
// MyView is the data type of the view I want to register and "MyView"
// is the name by which I want the data type to be identified within
// the IoC container.
_container.RegisterType<object, MyView>("MyView");
我按如下方式显示此视图。
_regionManager.RequestNavigate(
"MyRegion", // This is the name of the Region where the view should be displayed.
"MyView" // This is the registered name of the view in the IoC container.
);
在应用程序的其他地方,我需要在事件处理程序中删除此视图;但是,以下代码返回一个ArgumentNullException
.
_regionManager.Regions["MyRegion"].Remove(
_regionManager.Regions["MyRegion"].GetView("MyView")
);
这表明该RequestNavigate
方法没有添加MyView
到MyRegion
使用名称“MyView”。我知道如果我要使用该_regionManager.Add(MyView, "MyView")
方法,该GetView
方法将不会返回 null。不幸的是,RequestNavigate
似乎没有以相同的方式处理视图名称。当使用该方法添加视图时,有什么方法可以从区域中删除视图(按名称)RequestNavigate
?