Binding IsSelected on ToolWindow

Docking/MDI for WPF Forum

Posted 9 years ago by Bjørnar Sundsbø - Norway
Version: 9.1.0507
Avatar
Hi

I'm having problems binding the ToolWindow.IsSelected property to the same property in a ViewModel when using the MVVM pattern. The binding initially works, however when autohiding the toolwindow, this binding is detatched. I know this is because of the dynamically create and destroy mechanism of the container/docksite.

How can I work around this? I've tried creating a custom style with a setter for IsSelected, which results in no more luck than if i bind directly in the ToolWindow declaration. I've declared the local style inside inside docksite.Resources, but it is reverted to the original style for a toolwindow when docked again after autohide. I need to use different styles in the same window, so I can't overwrite the ToolWindowStyleKey.


Bjørnar Sundsbø

Comments (10)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Bjørnar,

The ToolWindows are not generally created/destroyed, they are just moved around in the visual/logical tree. If you set IsSelected on the ToolWindow in your XAML, then that should be retained for the entire life of the ToolWindow. Keep in mind though, that the IsSelected property is set internally (when selected/deselected), so your binding needs to be TwoWay.

If you can put together a small sample project that reproduces and email it over to our support address, then we can take a closer look. Be sure to remove any executables from the zip archive.


Actipro Software Support

Posted 9 years ago by Bjørnar Sundsbø - Norway
Avatar
Hi,

I'm working on a sample. I've been missing an attach file function for this forum so others can track the progress and updates for a thread.

Bjørnar


Bjørnar Sundsbø

Posted 9 years ago by Bjørnar Sundsbø - Norway
Avatar
Sample sent to support. Follow-up details has been emailed.

[Modified at 06/08/2010 07:24 AM]


Bjørnar Sundsbø

Posted 9 years ago by Bjørnar Sundsbø - Norway
Avatar
I tried using the latest release, but the issues were not resolved.


Bjørnar Sundsbø

Posted 9 years ago by Bjørnar Sundsbø - Norway
Avatar
I'd just like to add some information for those who might run into the same problem. The problem is due to the DataContext for the toolwindow being changed a few times when autohiding/docking, which leads to the binding being detached.

From what I understand, Actipro is looking into the problem.

As a workaround, I used attached behavior for the UserControl which is the content of the toolwindow. In this attached property, I get the DataContext of the Usercontrol and subscribing to property changed event of the IsSelected property of my ViewModel. I also traverse the logical tree for a ToolWindow ancestor. I save this in a dictionary. In the PropertyChanged event, I get the ToolWindow from this dictionary, and update the IsSelected property of the ToolWindow to be in sync with my ViewModel.

While writing this, I realize I could add a binding between my viewmodel and toolwindow through code, so the ViewModel will be updated when changing selection through toolwindow tabs.

The workaround works seems to work through developer testing, but we'll see how it behaves when the test department start hacking it apart :). An official fix would be most welcome, but I hope this is a workable workaround until then.

Bjørnar Sundsbø

[Modified at 06/08/2010 05:40 PM]


Bjørnar Sundsbø

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Bjørnar,

We were able to modify our code that moves the ToolWindow and ToolWindowContainer around to work around this issue. This fix will be included in the next maintenance release. This should fix the binding issue and the "resource not found" issue you see with using DynamicResource.


Actipro Software Support

Posted 9 years ago by Bjørnar Sundsbø - Norway
Avatar
Very good.


Bjørnar Sundsbø

Posted 9 years ago by Bjørnar Sundsbø - Norway
Avatar
I have just upgraded to the latest release of WPF Studio. This issue is still present in the latest version. When the toolwindow is placed in auto-hide mode, the datacontext detaches and it will no longer become selected when I set the IsSelected property to true. The sample and scenario is the same as when I initially posted this problem to the forums.

Bjørnar


Bjørnar Sundsbø

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Bjørnar,

I tried your sample again with the latest code and suggested fixes (from the support ticket) and it appears to work fine. The DataContext may be temporarily detached, as it's removed from the visual tree and reinserted in the new location. You can see that the DataContext is set by setting Title="{Binding}".

When a ToolWindow is auto-hidden, setting it's IsSelected to true does not cause it to fly-out. You would need to call Activate to display it in this case. There could be several auto-hidden ToolWindows in different groups that are considered "selected", but only 1 can be displayed at a time.


Actipro Software Support

Posted 9 years ago by Bjørnar Sundsbø - Norway
Avatar
It could be that I expected it to fly out (and dock) as that is the attached property behavior I implemented as a workaround, which is the expected behavior from the users point of view. I will check it out tomorrow.


Bjørnar Sundsbø

The latest build of this product (v2019.1 build 0683) 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.