Prism's IActiveAware + panes?

2 posts, 0 answers
  1. Kristoffer
    Kristoffer avatar
    158 posts
    Member since:
    Dec 2012

    Posted 07 Mar 2013 Link to this post

    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.)
  2. Ivo
    Ivo avatar
    390 posts

    Posted 12 Mar 2013 Link to this post

    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.

    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top