带导体和事件聚合器的分层导航

时间:2012-07-12 09:23:51

标签: c# wpf mvvm caliburn.micro eventaggregator

这是我的应用程序架构。请注意,我有指挥作为另一个指挥的孩子。我有IHandle让每个指挥从它的孩子接收消息。消息类型与我使用消息只是为了导航相同。我的问题是我将ShellView的EventAggregator传递给它的孩子们。

NewConnectionView的EventAggregator怎么样?因为我使用它的EventAggregator在ShellView上导航。因为它是孩子们在它的ActiveItem上导航。

如何在一个ViewModel中分离这两个EventAggregator。

ShellView& NewConnectionView ==> Conductor.Collection.OneActive

                                         +----------------------------------+
                                         | ShellView                 |_|[]|x|
                                         +----------------------------------+
                                         | +------------------------------+ |
                                         | |                              | |
                                         | |                              | |
                                         | |                              | |
                                         | |         ActiveItem           | |
                                         | |                              | |
                                         | |                              | |
                                         | |                              | |
                                         | +------------------------------+ |
                                         +----------------------------------+
                                                     /       \
                                                    /         \
                                                   /           \
                                                  /             \
                                                 /               \
                                                /                 \
                                               /                   \
                     +----------------------------------+    +----------------------------------+
                     | NewConnectionView         |_|[]|x|    | ConnectionListView        |_|[]|x|
                     +----------------------------------+    +----------------------------------+
                     | +------------------------------+ |    | TextBlock                        |
                     | | ComboBox                 | V | |    | +----------------------+ +-----+ |
                     | +------------------------------+ |    | |                      | | Btn | |
                     | +------------------------------+ |    | |                      | +-----+ |
                     | |                              | |    | |                      | +-----+ |
                     | |                              | |    | |                      | | Btn | |
                     | |                              | |    | |    DataGrid          | +-----+ |
                     | |         ActiveItem           | |    | |                      | +-----+ |
                     | |                              | |    | |                      | | Btn | |
                     | |                              | |    | |                      | +-----+ |
                     | |                              | |    | |                      |         |
                     | +------------------------------+ |    | +----------------------+         |
                     +----------------------------------+    +----------------------------------+
                                 /       \
                                /         \
                               /           \
                              /             \
                             /               \
                            /                 \
                           /                   \
 +----------------------------------+    +----------------------------------+
 | FileConnectionView        |_|[]|x|    | DatabaseConnectionView    |_|[]|x|
 +----------------------------------+    +----------------------------------+
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 +----------------------------------+    +----------------------------------+

目前,我的方法是使用NewConnectionShellView(Screen)作为NewConnectionView的(Conductor)父级来分隔EventAggregator。但问题是,我无法将NewConnectionView的子项的DisplayName显示到我的主窗口(ShellView)中。

请注意,我没有使用MEF。我的问题有解决方法吗?

                                         +----------------------------------+
                                         | ShellView                 |_|[]|x|
                                         +----------------------------------+
                                         | +------------------------------+ |
                                         | |                              | |
                                         | |                              | |
                                         | |                              | |
                                         | |         ActiveItem           | |
                                         | |                              | |
                                         | |                              | |
                                         | |                              | |
                                         | +------------------------------+ |
                                         +----------------------------------+
                                                     /       \
                                                    /         \
                                                   /           \
                                                  /             \
                                                 /               \
                                                /                 \
                                               /                   \
                     +----------------------------------+       +----------------------------------+ 
                     | NewConnectionShellView    |_|[]|x|       | ConnectionListView        |_|[]|x| 
                     +----------------------------------+       +----------------------------------+ 
                     | +------------------------------+ |       | TextBlock                        | 
                     | |                              | |       | +----------------------+ +-----+ | 
                     | |                              | |       | |                      | | Btn | | 
                     | |                              | |       | |                      | +-----+ |
                     | |                              | |       | |                      | +-----+ | 
                     | |                              | |       | |                      | | Btn | | 
                     | |                              | |       | |    DataGrid          | +-----+ | 
                     | |         ActiveItem           | |       | |                      | +-----+ | 
                     | |                              | |       | |                      | | Btn | | 
                     | |                              | |       | |                      | +-----+ | 
                     | |                              | |       | |                      |         | 
                     | +------------------------------+ |       | +----------------------+         | 
                     +----------------------------------+       +----------------------------------+ 
                                    |
                                    |
                                    |
                                    |
                                    |
                                    |
                                    |
                                    |
                                    V
                     +----------------------------------+
                     | NewConnectionView         |_|[]|x|
                     +----------------------------------+
                     | +------------------------------+ |
                     | | ComboBox                 | V | |
                     | +------------------------------+ |
                     | +------------------------------+ |
                     | |                              | |
                     | |                              | |
                     | |                              | |
                     | |         ActiveItem           | |
                     | |                              | |
                     | |                              | |
                     | |                              | |
                     | +------------------------------+ |
                     +----------------------------------+
                                 /       \
                                /         \
                               /           \
                              /             \
                             /               \
                            /                 \
                           /                   \
 +----------------------------------+    +----------------------------------+
 | FileConnectionView        |_|[]|x|    | DatabaseConnectionView    |_|[]|x|
 +----------------------------------+    +----------------------------------+
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 +----------------------------------+    +----------------------------------+

1 个答案:

答案 0 :(得分:0)

听起来您想要使用事件聚合器的一个实例进行shell /插件通信,并且每个插件使用一个实例进行视图间模型通信。我建议同时使用IoC容器并将shell事件聚合器注册为单例,然后使用具有容器引用的工厂来解析视图模型的实例。

您可以使用一种更改显示名称的消息类型,并在shell视图事件聚合器的实例上发布,以及一种更改当前活动项并在所有事件聚合器实例上使用的消息类型。