Create Tool Window Programmatically / Height

Docking/MDI for WPF Forum

Posted 13 years ago by Robert - RBWD
Version: 11.1.0542
Avatar
Hello,

I am trying to insert a new tool window into an existing layout (defined using XAML).

The base layout is very simple. In the middle, there is a workspace. Left to the workspace, there is just one tool window container (container 1) containing one tool window (window 1). The described setting has been defined using XAML. It is working.

Now, I want to dock a new tool window (window 2) programmatically to the bottom of the existing window 1. The new window should be initialized with a static height of 200 points.

As I read in this forum, it is not possible to apply a preferred height directly to the window, but only to an window container. Therefore, I decided to create a new window container, applying the preferred height, adding the new window as a child and finally docking the window container to window 1:
public MainWindow()
        {
            InitializeComponent();

            var container2 = new ToolWindowContainer();
            var window2 = new ToolWindow();
            window2.Title = "Tool Window 2";
            window2.Content = new Button { Content = "Content of Window 2" };
            container2.Items.Add(window2);

            container2.SetValue(DockSite.ControlSizeProperty, new Size(0.0, 200.0));
            container2.Dock(window1, Direction.Bottom);
        }
And the XAML Code defining the base layout:
<Window xmlns:docking="http://schemas.actiprosoftware.com/winfx/xaml/docking"  x:Class="DockingTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="483" Width="680">
    <Grid>
        <docking:DockSite Name="docksite">
            
            <docking:SplitContainer>
                <docking:ToolWindowContainer Name="container1">
                    <docking:ToolWindow Title="First Tool Window" Name="window1">
                        First Tool Window Content
                    </docking:ToolWindow>
                </docking:ToolWindowContainer>
                
                <docking:Workspace>
                    <docking:TabbedMdiHost>
                        <docking:TabbedMdiContainer>
                            <docking:DocumentWindow Title="My Document">
                                    My Document Content
                                </docking:DocumentWindow>
                        </docking:TabbedMdiContainer>
                    </docking:TabbedMdiHost>
                </docking:Workspace>
            </docking:SplitContainer>
        </docking:DockSite>
    </Grid>
</Window>
Please tell me what I am doing wrong. Running the code above shows that my programmatic operations do not take any effect. The new window 2 is not visible at all, neither with the correct nor with any height.

Sincerely,

Robert

[Modified at 05/13/2011 11:06 PM]

Comments (3)

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

There are few things wrong here. First, you don't need to create the ToolWindowContainer, as one will be created automatically for you when docking the ToolWindow.

The second issue is that you don't "register" the ToolWindow with the DockSite. If you use the default constructor like you do, then you need to manually add the ToolWindow to the DockSite.ToolWindows collection. There are other constructors that accepts a DockSite, which will registers the ToolWindow automatically also.

Finally, the ToolWindow is being added to the SplitContainer before it knows it's full size (and in a separate operation from your first ToolWindow). So you need to ensure that the SplitContainer has been loaded properly, so the ControlSize can be used.

So something like this will work:
this.Loaded += (s, e) => {
    var window2 = new ToolWindow();
    window2.Title = "Tool Window 2";
    window2.Content = new Button { Content = "Content of Window 2" };
    DockSite.SetControlSize(window2, new Size(100, 100)); // Make window smaller by default
    docksite.ToolWindows.Add(window2); // Register
    window2.Dock(window1, Direction.Bottom);
};


Actipro Software Support

Posted 13 years ago by Robert - RBWD
Avatar
Hi,

thank you for your reply. I adapted the changes to my code - it is working now. Perhaps you should consider simplifying the developers' process of defining the layout of tool windows. It should be possible to implement this control size property in a way which allows its usage, even if the whole layout had not been loaded at the time of the assignment. Otherweise, it is not very comfortable, specifically if you want to create multiple tool windows in a row which depend on each other.

I played a little bit around with my example and noticed that the tool windows at the left share the available height relatively when the window resizes. Is it possible to set up static sizes for particular windows? I do not want the second window to change its height if the window is resized. Compared to WPF grids, I would use the following code:

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/> <!-- Variable height -->
<RowDefinition Heihgt="Auto"/> <!-- Static height -->
</Grid.RowDefinitions>
<!-- Content -->
</Grid>
Thanks in advance,

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

Sorry, but we don't currently support fixed size ToolWindows. I've added this forum post to our TODO item for that feature, so you will be notified when it is implemented.


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.