我是wpf的新手。我必须在wpf中创建一个浮动的ToolBar,就像ms -Office2003工具栏。这样我就可以像Office2003一样,从上到下,从左到右,把它放在任何地方。
请帮帮我...............
发布于 2010-05-22 16:24:21
我建议你看看第三方控件库。Syncfusion是一个商业产品,它的essential tools collection中包含一个停靠管理器组件。不过,它并不真的像office 2k3 (更像是Visual Studio)。还有一款on codeplex,我敢肯定还有其他几款价格各不相同。
对于工具栏从主工具栏区域的实际移除,我相信standard WPF toolbar控件已经支持这一点。至少你可以在toolbar tray中移动它们。
发布于 2010-05-22 16:17:39
对于简单的停靠,您将使用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>当然,您可以使用更适合您的需求的类来代替Button。
然而,当你需要一个带有浮动窗口的窗口系统时,你将不得不恢复到第三方库,因为WPF没有这个库,而且很难滚动你自己的库。下面是一些库:
如果您真正需要的只是停靠浮动工具栏(而不是其他窗口),则可以将ToolBar class与ToolBarTray class结合使用。但是您需要编写代码来检测拖动,从可视化树中删除ToolBar元素,然后将其作为根可视化添加到您自己的窗口或HwndSource中。然后,您需要检测窗口何时位于拖放区域之上,以便将ToolBar从窗口移动到主窗口的可视化树并关闭另一个窗口。
发布于 2013-08-01 15:15:30
要创建工具栏并向其中添加按钮,此代码可能会帮助您...
Toolbar m = new ToolBar();//创建名为m的工具栏
//可以设置更多的属性
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;
}
}https://stackoverflow.com/questions/2887386
复制相似问题