2012-07-12 32 views
4

這是我的應用程序架構。請注意,我有導體作爲另一位指揮的孩子。我有IHandle讓每個售票員從它的孩子那裏接收消息。消息類型與我用於導航的消息相同。我的問題是我將ShellView的EventAggregator傳遞給它的子節點。帶導體和事件聚合器的分層導航

NewConnectionView的EventAggregator怎麼樣?因爲我使用它的EventAggregator在ShellView上進行導航。因爲它是兒童導航它的ActiveItem。

如何在一個ViewModel中分離這2個EventAggregators。

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(屏幕)作爲NewConnectionView的(指揮)父母的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| 
+----------------------------------+ +----------------------------------+ 
|         | |         | 
|         | |         | 
|         | |         | 
|         | |         | 
|         | |         | 
|         | |         | 
|         | |         | 
|         | |         | 
|         | |         | 
|         | |         | 
|         | |         | 
|         | |         | 
+----------------------------------+ +----------------------------------+ 
+0

對於ASCII藝術的+1 – juFo 2013-10-08 11:45:40

回答

0

這聽起來像你要使用的事件聚合殼/插件進行通信的一個實例,每一個插件實例視圖模型間的溝通。我建議使用兩個IoC容器並將shell事件聚合器註冊爲單例,然後使用引用容器的工廠來解析視圖模型的實例。

您可以擁有一種消息類型,它可以更改顯示名稱並在shell視圖事件聚合器實例上發佈,還可以有一種消息類型更改當前活動項目並在所有事件聚合器實例上使用。

+0

使用IoC意味着我也使用MEF嗎? – asakura89 2012-07-16 09:44:08

+0

或ninject,autofac等MEF有點不同! .NET書中的Dependancy Injection很好地描述了這些差異。 – 2012-07-17 04:32:04

+0

是的,沒有什麼可以阻止您使用MEF爲您的插件體系結構,而另一個IoC容器則用於您的常規應用程序基礎結構。 – devdigital 2012-07-17 08:25:26