如何以编程方式在工具栏面板中添加工具栏?

发布于 2024-09-03 11:14:19 字数 417 浏览 0 评论 0原文

我想将我的 ToolBar 添加到代码隐藏的 ToolBarPanel 中。 我看到了 Button & 的一个例子Canvas 面板。

这是代码:

Canvas.SetLeft(newButton, containerPoint.X - objectPoint.X);
Canvas.SetTop(newButton, containerPoint.Y - objectPoint.Y); 

我怎样才能用 ToolBar & 达到同样的效果? ToolBarPanel而不是使用Canvas & 按钮

I want to add my ToolBar inside the ToolBarPanel in codebehind.
I saw one example of Button & Canvas panel.

Here is the code:

Canvas.SetLeft(newButton, containerPoint.X - objectPoint.X);
Canvas.SetTop(newButton, containerPoint.Y - objectPoint.Y); 

How can I achive samething with ToolBar & ToolBarPanelinstead of using Canvas & Button?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

水晶透心 2024-09-10 11:14:19

您提供的代码不是将按钮添加到画布,而是设置扩展属性来指定按钮所在的坐标(如果按钮放置在 Canvas 面板上)。

ToolBarPanelToolBar 用来排列其项目的原始面板。除非您想自定义行为,否则您应该只使用 ToolBar(可选)将其放入 ToolBarTray 中。

ToolBar 是一个 ItemsControl(例如,就像 ListBox),因此要从代码添加按钮,请将其添加到面板的 Items< /代码>集合:

toolbar.Items.Add(newButton);

The code you gave is not adding the button to canvas, it sets extension properties that specify coordinates the button will be located at, if it is placed on Canvas panel.

ToolBarPanel is a primitive panel used by ToolBar to arrange its items. Unless you want to customize behavior you should be just using ToolBar optionally placing it into ToolBarTray.

ToolBar is an ItemsControl (just like ListBox for example), so to add a button from code, add it to panel's Items collection:

toolbar.Items.Add(newButton);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文