ashish semwal
ashish semwal

Reputation: 99

how to create a docking(floating) toolbar in wpf

I am new to wpf. I have to create a floating ToolBar in wpf like the ms - office 2003 toolbar. So that I can place it anywhere top - bottom, left- right as same as it was in office 2003.

Please help me .......................

Upvotes: 2

Views: 14907

Answers (3)

Pavan R Bhupalam
Pavan R Bhupalam

Reputation: 69

to create tool bar and add buttons to it, this code may help you...

 Toolbar m = new ToolBar();

//creates toolbar with name m

// you can set som more properties

m.Divider = true;
m.DropDownArrows = true;
m.Size = new System.Drawing.Size(250, 25);
m.Wrappable = true;

ToolBarButton tb1 = new ToolBarButton();
ToolBarButton tb2 = new ToolBarButton();
ToolBarButton tb3 = new ToolBarButton();

tb1.Text = "Admin";
tb2.Text = "Teacher";
tb3.Text = "Student";

m.Buttons.Add(tb1);
m.Buttons.Add(tb2);
m.Buttons.Add(tb3);
Controls.Add(m);

private void m_Clicked(Object sender,
                        ToolBarButtonClickEventArgs e)
{

switch (m.Buttons.IndexOf(e.Button))
    {
        case 1:
            MessageBox.Show("Admin logged in");
            break;
        case 2:
             MessageBox.Show("Teacher logged");            
            break;
        case 3:MessageBox.Show("Student loged in");            
            break;
                case 4:
            this.Close();   
            break;
}
}

Upvotes: -3

bitbonk
bitbonk

Reputation: 49599

For the plain docking you would use the DockPanel:

<DockPanel>
    <Button DockPanel.Dock="Top">This would be a toolbar at the top</Button>
    <Butto>This would the main work area</Button>
</DockPanel>

<DockPanel>
    <Button DockPanel.Dock="Left">This would be a toolbar at the left</Button>
    <Button>This would the main work area</Button>
</DockPanel>

Instead of Button you would of course use the classes that are more apropriate for your needs.

However when you needs a windowing system with floating windows you will have to revert to a 3rd party library because it WPF does not have it and it would be pretty hard to roll your own. Here are some libs:

If all you really need is the docking floating toolbar (and no other windows) you can use the ToolBar class in conjunction with the ToolBarTray class. But you will need to write code to detect the drag, remove the ToolBar element from the visual tree, and then add it as a root visual to your own Window or HwndSource. You'll then need to detect when the window is over your drop zone to move the ToolBar from the window to the main window's visual tree and close the other window.

Upvotes: 11

Isak Savo
Isak Savo

Reputation: 35884

I recommend you look at third party control libraries for this. Syncfusion is a commercial product that contains a dock manager component in their essential tools collection. It's not really like office 2k3 though (more like Visual Studio). There is also one on codeplex and I'm sure there are several others at various price ranges.

For the actual undocking of toolbars from the main toolbar area I believe the standard WPF toolbar controls already supports this. At least you can move them around within a toolbar tray.

Upvotes: 1

Related Questions