Programatically adding buttons to Toolwindow

Docking/MDI for WPF Forum

Posted 13 years ago by Bret Naughton
Version: 11.1.0540

I am currently using toolwindows as my main window type within my application/docksite (doing this for aesthetic reasons as I prefer the look of the toolwindow tabs instead of the classic documentwindow tab)

What I am trying to achieve is as follows..... I want to dynamically/programatically show buttons on the toolwindow /header depending on preferences; security options & the particular app that I am hosting in the instance of the toolwindow.

So the user could create an instance of the toolwindow that has a print; refresh; and preview button in it's header tab..... but with another instance, the contents/permissions of the toolwindow dictates that they can only see a security button.

Therefore I am trying to see if you have any examples of VB code for programatically creating a button on the toolwindow tab (I think this is possible by editing XAML as seen in the 'Buttons on selected tabs' section of the sample application, but I am unable to find anything that I can generate from VB code). I can then create some classes to hold the different variances for the button (title; graphic; function code) and then call/add to the toolwindow dynamically depending on what the particular requirement & logic that I then define. [I am also presuming that I can add any image I want as the button within the toolwindow tab/header.]

On a further question, as I mentioned I am using the toolwindow for aesthetic reasons as I prefer the square stretched tab/header that stretched across the docksite. Am I painting myself into a corner using toolwindows for everything, or would I be better using document windows and changing templates (if even possible)to replicate toolwindow aesthetics. I just want to make sure that I not doing anything unnatural in terms of WPF & future development.

Please let me know if I can provide any further information or screen dumps of my current application.


Comments (3)

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

The choice between using ToolWindows and DocumentWindows really has to do with the functionality they provide. The DocumentWindows are intended to be presented in a MDI area or possibly floated. ToolWindows can, by default, be placed anywhere. If you don't have a MDI area, then you can probably ignore DocumentWindows. If you'd like to have a MDI area, then you'd probably be better off creating a custom control template for the DocumentWindow type that uses a square look.

We don't have any examples beyond what is included in our Sample Browser. Unfortunately, none of those those how to dynamically populate the Header/HeaderTemplate from your code-behind. But the Header property can be set to any UIElement, so you'd just create say a Grid or DockPanel and add child controls as needed. Alternatively, you can build up a DataTemplate using FrameworkElementFactory and assign that to the HeaderTemplate.

If you are using 2011.1, then you're best bet would be to create a custom type that derives from ToolWindow, say MyToolWindow. Then you can copy the default Style for the ToolWindow and retarget it for your type. You can then add custom properties to MyToolWindow (i.e. CanRefresh) and you'd then tweak the control template to include a refresh button whose visibility is control by your new property.

Actipro Software Support

Posted 13 years ago by Bret Naughton
Thanks for your last reply. I am going to go with the method of creating elements and populating the header accordingly.

In preparation for this, I have currently set my main docksite with the following settings...

Me.ToolWindowsTabPlacement = TabPlacement.Top
Me.UseHostedAutoHidePopups = False
Me.CanToolWindowsRaft = False
Me.CanToolWindowsAutoHide = False

Me.ToolWindowsSingleTabLayoutBehavior = SingleTabLayoutBehavior.Stretch
Me.ToolWindowsHaveTitleBars = False
Me.ToolWindowsHaveOptions = True
Me.ClosePerContainer = True

These allow me to have my toolwindows with the tabs stretched out for when they are not tabbed to each other. For now it also allows me to see my ImageSource whether tabbed/untabbed. When I get to the next phase of development/release, I will be able to add my own header contents (custom buttons) etc.

However, I have noticed the option/close buttons are not on the tab-header (although right clicking does provide this option). Is there a command/property for setting the close/options buttons on the tabs. Sorry if it is available, just can't seem to find it.

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

Those buttons are only shown on the title bar, which you have hidden. The Buttons on Tabs QuickStart shows how the buttons can be added to the selected tab, which I believe is what you are looking for.

Actipro Software Support

The latest build of this product (v24.1.2) 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.