How to implement "DeepActiveItem"

Topics: Getting Started, UI Architecture
Jul 13, 2011 at 9:04 AM
Edited Jul 13, 2011 at 9:05 AM

My ShellViewModel inherits from Conductor(Of IScreen).Collection.OneActive, as usual.

Now one of this Items could be a StructureViewModel which inherits from  Conductor(Of IScreen).Collection.OneActive  as well.

For the time being I'm trying to bind a RibbonButton (or Button in a CommandBar, doesn't matter at this point) via
cal:Message.Attach = "Test" and cal:Message.Target = "{Binding ActiveItem}  to the active Screen.
But the StructureViewModel does not have a Method "Test", but the ActiveItem of THIS Conductor does have.

So I was thinking about how to implement a "DeepActiveItem"-Method iterating throug all Screens, checking whether
the ActiveItem is a conductor and then iterating through the "Sub-Screens". But currently I got the problem
that I'm not aware of that a SubScreen has been activated.

Maybe the idea is completely wrong and I would like to get some ideas from your end.

I'm not sure whether IChild<T> might help, because it might be possible that one of the screens
can be used without a parent.

Any reply would be highly appreciated.



PS: Example 

     ShellViewModel (Conductor)

              TestAViewModel (Screen, implementing Test-method)

              StructureViewModel (Conductor)

                        StructureEditorViewModel (Screen, implementing Test-method)

                        StructureViewwerViewModel (Screen, implementing Test-method)

              TestBViewModel (Screen, implementing Test-method)



Jul 13, 2011 at 2:07 PM

If I understand correctly, I think your easiest solution might be to ada a Test method to ShellViewModel and then just have it call the corresponding method on the ActiveItem.

Jul 13, 2011 at 2:17 PM

Would be possible, but I don't like to have several  extra-methods within ShellViewModel. The sample above is quite simple, for demonstration.

But I just found sourceode of a CaliburnWindowManager using the Infragistics-DockManager and I'm just trying to extend this,
in order to meet the above requirements. Could take a while.

Jul 13, 2011 at 6:54 PM

(sorry for my bad english) If I understand you well, I have a similar scenario, multiple screens and sub-screens that are controlled by one menu bar on the ShellView. What i ended up doing is whenever I activate a screen, I use the EventAggregator to publish the active screen. On my toolbar I have a property "ActiveScreen" and there I can test if the screen implements some interface (ex ICanSave) and enable/disable the toolbar buttons. On a button click i just call the method exposed by the interface, something like:

(ActiveScreen as ICanSave).Save()