如何以编程方式在工具栏面板中添加工具栏?
我想将我的 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
& ToolBarPanel
instead of using Canvas
& Button
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您提供的代码不是将按钮添加到画布,而是设置扩展属性来指定按钮所在的坐标(如果按钮放置在
Canvas
面板上)。ToolBarPanel
是ToolBar
用来排列其项目的原始面板。除非您想自定义行为,否则您应该只使用ToolBar
(可选)将其放入ToolBarTray
中。ToolBar
是一个ItemsControl
(例如,就像ListBox
),因此要从代码添加按钮,请将其添加到面板的Items< /代码>集合:
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 byToolBar
to arrange its items. Unless you want to customize behavior you should be just usingToolBar
optionally placing it intoToolBarTray
.ToolBar
is anItemsControl
(just likeListBox
for example), so to add a button from code, add it to panel'sItems
collection: