cannont bind to ActiveWindow/LastActiveDocument

Docking/MDI for WPF Forum

Posted 13 years ago by Joachim Blaurock
Version: 11.1.0541
Avatar
Hi,

I am trying to use the Docking control in an MVVM scenario. I need to disable certain toolwindows dependend on which Document window is selected.

To get the active, selected document window I tried to databind my view model to "ActiveWindow" and "LastActiveDocument", but I get an error "DockSite.ActiveWindow cannot be set because it does not have an accessible set accessor".

I have set my binding to "Mode=OneWay", but obviously Wpf somehow still does something under the hood with the setter, if the dp property is not explicitely marked as readonly.

Is this a bug in your control or how can I get around this problem?

BTW: I would have expected a "DocumentItemsSource.SelectedDocument" property to get the active view model of the active selected document window which would make things a lot easier.

regards
Joachim

Comments (7)

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

You would need to use OneWayToSource if you put a binding on ActiveWindow or LastActiveDocument, as those properties are read-only. The problem with a "SelectedDocument" property, is that there can be several selected windows (some of which may be floating).

You would probably have to hook into the WindowActivated/WindowDeactivated event of the DockSite. If OneWayToSource doesn't work for you.


Actipro Software Support

Posted 13 years ago by Joachim Blaurock
Avatar
Hi,

there is no difference as to whether I use "OneWay" or "OneWayToSource". I get the same compiler error saying "...not accesible set accessor". It seems that the read-only dp property is not correctly implemented here.

I would very much like to avoid registering to events and do it rather the MVVM way. Actually the MVVM support of your control is the only reason why I am evaluating it.
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Joachim,

Unfortunately, this appears to be a limitation imposed by WPF, which is supposedly by design:

http://connect.microsoft.com/VisualStudio/feedback/details/540833/onewaytosource-binding-from-a-readonly-dependency-property
https://connect.microsoft.com/WPF/feedback/details/523865/read-only-dependency-properties-does-not-support-onewaytosource-bindings

We've marked down a TODO item to see about making the ActiveWindow property read/write in the future.


Actipro Software Support

Posted 13 years ago by Joachim Blaurock
Avatar
Ok, i broke my mvvm pattern for now and registered to the Window.Activated event. But I am running into the next problem:

I have a rather simple scenario where I have several DocumentWindows containing different kind of documents, with a different ui. Now I need to show certain Toolwindows dependent on the DocumentWindow selected. In other words, I need to show/hide Toolwindows on ActiveDocument changed.

The logic of which tool window to show with which document window I want to put in my document´s view model. But again how can I do simple operations like showing/hiding a toolwindow via mvvm? I tried to bind the DockingWindow.IsOpen property, but again, this is read-only!
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Joachim,

We don't currently have a proeprty that can be used to close ToolWindows. As you mention, the IsOpen property tells you whether the window is open, but it's currently read-only.

We've updated this to be a read/write property for the next maintenance release, so you can add a two-way binding or set it explicitly. Keep in mind though, that setting IsOpen to true is the same as calling Open() and setting it to false is the same as calling Close(). So the only real benefit of it being read/write is being able to add a two-way binding.


Actipro Software Support

Posted 13 years ago by Joachim Blaurock
Avatar
Hi, yes, having IsOpen as a writable dp will definitely improve the mvvm capability.

But I am still struggling with controlling toolwindows that are dependend on docwindows.

I registered the DockingSite.WindowActivated event to find out when the user selects a certain tabpage (DocumentWindow). Through this event I set the "ActiveDocumentViewModel" property in my ViewModel. One Document now makes sure that a certain ToolWindow is displayed (AdminMode) and another Document makes sure that if that Toolwindow is open, it has to be closed (UserMode).

The problem now is, that whenever I close a ToolWindow from my view model by calling

DockSite.ToolWindows.Remove(myAdminToolWindow);

this will raise a WindowActivate event of the first Tab in the document window!? This results in a strange User Experience, whenever the user selects a document tab that hides a tool window, the first document tab is selected and the user has to click again on the tab page to change back.
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Joachim,

It's very hard to tell without seeing it in action. If you can please put together a small sample project that reproduces your issue and email it over then we can take a closer look. Be sure to remove any executables or change the extension of the zip file to ensure it gets past our email filters.

Assuming you have the DockItem.ToolItemsSource property bound to a collection of your tool window view-models, you shouldn't need to explicitly remove the ToolWindow from the DockSite like have above.


Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.