2010-05-22 137 views

回答

1

我建议你看看第三方控制库。 Syncfusion是一款商业产品,其中包含一个dock manager组件。它不像真正的Office 2k3(更像Visual Studio)。还有一个on codeplex,我敢肯定还有其他几个价格不同的人。

对于工具栏从主工具栏区域实际脱离连接,我认为standard WPF toolbar控件已经支持这一点。至少你可以在toolbar tray之间移动它们。

11

对于普通的对接,你会使用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> 

而是按钮,当然,你会使用为您的需求更apropriate类。

但是,当你需要一个带有浮动窗口的窗口系统时,你将不得不恢复到第三方库,因为它没有WPF,它将很难推出自己的。下面是一些库:

如果您真正需要的是对接浮动工具栏(并且没有其他窗口),则可以将ToolBar classToolBarTray class一起使用。但是您需要编写代码来检测拖动,从可视化树中移除ToolBar元素,然后将其作为根视觉添加到您自己的Window或HwndSource中。然后,您需要检测窗口何时位于放置区域,以便将ToolBar从窗口移动到主窗口的可视化树并关闭另一个窗口。

+0

我需要我的工具栏与对接窗口,所以我如何可以与dockpanel.c居住你请解释.. – 2010-05-22 08:22:45

+0

我编辑了相应的职位。 – bitbonk 2010-05-22 08:30:36

+0

随意标记你喜欢的答案作为答案。 :) – bitbonk 2010-05-22 09:52:35

-3

创建工具栏和按钮添加到它,这个代码可以帮助你......

Toolbar m = new ToolBar(); 

//与名为M

创建工具栏//你可以设置SOM多个属性

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; 
} 
} 
+2

这不会回答所问的具体问题(即如何制作*浮动工具栏)。 – crashmstr 2014-01-08 15:25:21