mvvm and Selected Document

Docking/MDI for WPF Forum

Posted 13 years ago by shlomi R
Version: 11.1.0543
Avatar
Hi,
I'm using the new mvvm implementation, and it works great.

I got to a point where I need to set the active document from the view model.

Apparently the DocSite.ActiveDocument and the DockingWindow.IsSelected are read only properties.

One way to do that is by using the DocumentWindow.Activate method.
But it will break the mvvm pattern.

Is there any other way to do that?

[Modified at 06/18/2011 01:26 PM]

Comments (3)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

You are correct. You'd have to keep the "selected" window in your View-Model in sync with the DockSite manually (using the Activate method and WindowActivated event). In our Prism Interop, this is performed using an attached behavior, but this can easily be applied to general MVVM applications as well.

This doesn't break the MVVM pattern. MVVM doesn't require that bindings must be used, just that the logical concerns be separated. The native WPF TreeView cannot use a two-way binding to update it's selection, but it can still be used in MVVM applications. With the DockSite, the "selection" is even more fuzzy. There can be any number of windows visibile, and technically selected (as their content is displayed).


Actipro Software Support

Posted 12 years ago by Wesley Zink - Senior Software Engineer, Proteus Biomedical
Avatar
I'm also trying to implement this functionality. Could you provide further details on the behavior that you are referring to? I did not see any IsActive or IsSelected dependency properties in the Prism Interop example.

Could you provide a more concrete MVVM example which shows how one could Activate a DockingWindow in the context of your MvvmFeatures example. Code would be much appreciated.

Wesley Zink Senior Automation Software Engineer Proteus Biomedical, Inc. 3956 Point Eden Way Hayward, CA 94545 Phone: 650-632-4031 ext 454

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Wesley,

Our Sample Browser includes an MVVM sample for our Docking & MDI for WPF product. That sample uses an attached behavior called DockSiteViewModelBehavior, which allows the docking position to be specified in the view models (instead of hard-coded in the UI). Additional logic can be added into this behavior that hooks into the WindowActivated event, and a similar event on the view model for the "selected document" changing. The behavior would then have to ensure that the two are keep in sync (i.e. if the view model's selected document changes, then you'd Activate the associated window in the DockSite and vice versa).


Actipro Software Support

The latest build of this product (v24.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.