Reputation: 99
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
?
Upvotes: 0
Views: 2382
Reputation: 2979
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);
Upvotes: 1