Access ToolWindowContainer on create

Docking/MDI for WPF Forum

Posted 9 years ago by Bjørnar Sundsbø - Norway
Version: 10.2.0533
Avatar
I need to set an attached DependencyProperty on all newly created ToolWindowContainers to place the tabs at the correct location (not the ToolWindowTabPlacement property). I've been able to fix it for most scenarios, however it does not work when an entire ToolWindowContainer is moved from floating state to docked.

I've been trying to find any collection to monitor for changes (such as AutoHideLeftContainers) though I've had no luck in finding any collection containing docked ToolWindowContainers.

Can you help me out with this?


Bjørnar Sundsbø

Comments (4)

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

You can use an implicit Style for the ToolWindowContainer type, but it would need to be in your application resources to be applied to ToolWindowContainers in floating windows.

Alternatively, you can create a custom DockSite and override CreateRaftingWindow. Then you'd call the base class method and if the return result is a Window, then you can add any implicit Styles into it's resources.


Actipro Software Support

Posted 9 years ago by Bjørnar Sundsbø - Norway
Avatar
I tried to override CreateRaftingWindow and was able to find the ToolWindowContainer from the RaftingHost's content. However at the time of creating the rafting window, I do not know which side of the workspace any ToolWindow inside the container "lives" on. I can't set the attached property since I do not have this information.

The same is the case for using a style.

Is there nowhere to get the containers when a toolwindow is docked (being docked)? I use most of the events from the DockSite already, but the event I'm looking for is missing, and I have not yet found anything to monitor to get the same "event". I have yet to find any property where the docked toolwindows/containsers reside inside the DockSite.


Bjørnar Sundsbø

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

That's correct, the ToolWindowContainer won't be added until after the rafting window has been created. Generally, you can use an implicit Style to set a custom attached property, which tells you when it's been created. These are generally referred to as attached behaviors. So if you have a MyType.IsManagedProperty which is defined as an attached property of type bool and defaults to false, then you can set that property to true in the implicit Style for ToolWindowContainer. Then in a property change handler for IsManagedProperty, the sender will be the ToolWindowContainer. Once you have that, you can set your tab placement.

Other than that, there isn't a "master" list of all the ToolWindowContainers.


Actipro Software Support

Posted 9 years ago by Bjørnar Sundsbø - Norway
Avatar
This actually works quite well. The only drawback is that I had to subscribe to the Loaded event to apply the TabPlacement property, and then unsubscribe the event. The reason is that I am not able to find the direction of the ToolWindows in the container at create time, only when it is loaded and rendered to the UI.

Using this approach I could remove all the eventhandlers I had on the DockSite where I did the direction lookup and tab placement.

Now all my logic for placing the toolwindow tabs for a ToolWindowContainer, where tabs are placed along the edges of the docksite, is inside two attached properties.

ToolWindowContainerTabPlacement - Direction where the tabs should be rendered.
IsManagingToolWindowTabPlacement - Hooks into the Loaded event. Inside the loaded event I get the first ToolWindow and GetDirectionRelativeToWorkspace(toolWindow). I then set the ToolWindowContainerTabPlacement property to the direction and unsubscribe the Loaded event.

Then I do minor changes to the the ToolWindowContainer's ControlTemplate so I can render the tabs at the four directions (Top, Bottom, Left, Right) through triggers checking the ToolWindowContainerTabPlacement attached property (in addition to setting the IsManagingToolWindowTabPlacement property through a setter in the style.

Brilliant! This should be fairly simple to make part of the product. Only you should add a property on the DockSite so the user can let the docksite know if this behaviour should be applied.

Bjørnar Sundsbø


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.