在我的PRISM-App中,用户可以在TabView中打开模块的视图(Navigate("TestView")
)。现在我想通过OnCloseTab("TestView")
关闭此视图,但注册视图没有名称。是否有可能通过regionManager.RequestNavigate将其名称注册为View以便将其从区域中删除?
public class MainWindowViewModel: BindableBase
{
...
private void Navigate(string uri)
{
this.regionManager.RequestNavigate("TabRegion", uri);
}
private void OnCloseTab(string uri)
{
IRegion region = this.regionManager.Regions["TabRegion"];
object view = region.GetView(uri);
if (view != null)
{
region.Remove(view);
}
}
}
模块注册在我的引导程序是这样的:
protected override void ConfigureModuleCatalog()
{
base.ConfigureModuleCatalog();
ModuleCatalog moduleCatalog = (ModuleCatalog)this.ModuleCatalog;
Type modulePType = typeof(Module.ProductionData.ProductionDataModule);
moduleCatalog.AddModule(typeof(Module.ProductionData.ProductionDataModule));
}
它适用于:
IRegion region = regionManager.Regions["TabRegion"];
object view = region.GetView("TestView");
if (view == null)
{
view = ServiceLocator.Current.GetInstance<Views.TestView>();
region.Add(view, "TestView");
}
但MainWindowViewModel不知道有关模块的意见。有没有办法删除视图,当它没有名称?感谢任何提醒
谢谢为了你的帮助,卢克。我发布了我的最终解决方案。 – Max