【发布时间】:2010-12-06 10:47:27
【问题描述】:
我有一个 prism 应用,其中包含一个 Shell.xaml(带有 MainRegion)、ShellViewModel.cs。
应用程序启动时会打开此 Shell 窗口。现在我想打开第二个包含相同 shell 窗口(Shell.xaml、ShellViewModel)的 Popup-Window。
Shell 定义类似于 prism StockTraderRI 示例中的定义。 Shell.xaml 包含一个 MainRegion(非常简化的源代码):
<Window x:Class="Bsoft.Test.Shell"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cal="http://www.codeplex.com/CompositeWPF"
Title="MainWindow" Height="550" Width="825">
<Grid>
<ContentControl cal:RegionManager.RegionName="MainRegion"/>
</Grid>
</Window>
后面的代码只包含基本的 ViewModel 参考:
namespace Bsoft.Test.bmedApp
{
[Export]
public partial class Shell : Window
{
[ImportingConstructor]
public Shell()
{
InitializeComponent();
}
[Import]
ShellViewModel ViewModel
{
set
{
this.DataContext = value;
}
}
}
}
ShellViewModel 由 MEF 加载器自动插入:
namespace Bsoft.Test.bmedApp
{
[Export]
public class ShellViewModel : NotificationObject
{
[ImportingConstructor]
public ShellViewModel()
{
}
}
}
这确实按预期工作。
现在我想再次打开 shell 窗口作为弹出窗口。使用以下方法将 Shell 和 ViewModel 标记为不共享很容易:
[PartCreationPolicy(CreationPolicy.NonShared)]
但我的问题是:
1) 我将其他视图(模型)加载到 MainRegion。我如何告诉程序是否应该将 View(Model) 加载到主 Shell MainRegion 或弹出窗口 MainRegion 中?我想我需要作用域的 RegionManager,但我不知道如何使用它们。
2) 我有一些事件 (EventAggregator) 用于加载到区域中的视图来传达通知和命令(状态更新、视图关闭、错误)以供 Shell 报告。如何将主要的 shell 事件与弹出窗口事件分开(因为两者都是同一个 shell)?
我希望能够打开几个弹出窗口,因此对两者使用不同的区域名称对我来说是不够的,我需要更多的分离。也许有办法创建一个单独的内部 prism/mef/region/container 框架??
【问题讨论】:
-
我只是想知道为什么要再次打开一个shell?如果 shell 是您需要重用的视图,为什么不将细节概括出来,在其上创建两个包装器。一个是shell,另一个是可以多次打开的视图。
-
外壳是我的包装器,包含一个带有许多项目的 TabControl。我只是希望用户能够为相同类型的视图打开第二个包装器,这样他就可以并排查看它们。
-
无论如何,我不知道如何实现您的建议:如何为两个或多个视图中的每一个分隔区域和事件。