4

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

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

如何在一个 ViewModel 中分离这 2 个 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|
 +----------------------------------+    +----------------------------------+
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 |                                  |    |                                  |
 +----------------------------------+    +----------------------------------+
4

1 回答 1

0

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

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

于 2012-07-15T10:31:49.823 回答