I wrote an addin that exports a document and a toolbar. Now I want the toolbar to be visible only if current active document is of my type. How can I get the active document from layout manager/workbench?
asked 03 May '12, 13:35
Getting the current document might not be necessary if all you want to do is make a toolbar visible/hidden. The toolbars have a VisibleCondition property, which I haven't played with, but might be exactly what you're looking for.
That being said, I briefly wondered recently in my SBC adventures, how I would reference the current document, although I have not yet needed to actually do it. (My post from last week needed an instance of a View to reference the matching instance of its ViewModel, which is a similar issue but not exactly the same).
I have found (empirically, mind you) that switching tabs triggers the DataContextChanged event for content within the data template, where the new context is the new document. You could add an OnTabChanged method in your document class and use a static variable to track the current document. Going back to the ol' Recipe example (abbreviated)...
It would be nice to have some of this more generic, which you could do by a) write a DocumentManager service, b) extend the AbstractDocument class with the new methods, and c) wire them together. Seems like this is common enough that it might be desirable to have in SoapBox Core.
answered 03 May '12, 15:16