This is a migrated thread and some comments may be shown as answers.

Prism's IActiveAware + panes?

1 Answer 194 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Kristoffer
Top achievements
Rank 1
Kristoffer asked on 07 Mar 2013, 04:06 PM
Using Prism v4 (with MEF for that matter) + MVVM. There is a convenient way to let views/viewmodels be aware of the view's state. Simply implement the IActiveAware interface in the viewmodel (and/or the view) and make sure the view is attached to a region. Now, when the view becomes active/inactive the IsActive property of the viewmodel will reflect its state.

Now, I have something like 20 different panes but not all of them are visible at all times. Just like in Visual Studio, some documents need certain panes. E.g. if you open an image in Visual Studio, the Colors pane becomes visible. For commands and messages, this implies a problem. Again in Visual Studio, consider the Ins shortcut in the Image editor. Issuing this command adds a new image type. However, if you issue this command in your source code, you toggle insert mode. Ok, so a command can mean different things depending on context or "activeness" if you'd like. If the active document is an image, the command should be handled differently than if it is a text file.

So for my ImageViewModel I have an OpenCommand. The same goes for TextFileViewModel. Now, If I press the Ins key the active document's corresponding OpenCommand should be issued. If I had two views - ImageView and TextFileView - I would simply implement the IActiveAware interface and issue a DelegateCommand (which is IActiveAware) to make sure the right OpenCommand is triggered. But... I have my views in panes. Now what?

How can I successfully handle IActiveAware (or other suitable interface) for my RadDocking/RadDocumentPane/RadPane hierarchy?

E.g. When my active RadDocumentPane contains a TextFileView, then my TextFileViewModel should be aware of this "Text File state". Similarly, if my active RadDocumentPane contains a ImageView, then my ImageViewModel should be aware of this "Image File state".

This is needed not only to correctly coordinate commands, but also to allow multiple viewmodel instances know if they should respond to certain messages/events. Since panes can be pinned, hidden etc, it's not completely obvious how this should be handled. Ideas?

UPDATE: I believe a good start would be to let the setter of ActivePane issue the Microsoft.Practices.Prism.IActiveAware interface in the same way Prism does it. (See RegionActiveAwareBehavior.cs in Prism 4.)

1 Answer, 1 is accepted

Sort by
0
Ivo
Telerik team
answered on 12 Mar 2013, 05:46 PM
Hi Kristoffer,

Apart from the RadDocking's ActivePane property, both RadPane and RadDocumentPane have an IsActive property, Activated and Deactivated events that I believe can help you. They will be suitable for both handling the IActiveAware interface and allowing viewmodels to "know" whether they should respond to certain events.

Greetings,
Ivo
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Docking
Asked by
Kristoffer
Top achievements
Rank 1
Answers by
Ivo
Telerik team
Share this question
or