How add items inside the toolbar?
-
Monday, January 07, 2008 5:46 PM
Hi,
I'm trying to add contrls(Button, ListBox, TextBox) inside the toolBar.
I'm using VS 2008 with C#...
I would like to add these controls in visual with the controls is ready...
How do it?
I hope you help me.
Thank you,
All Replies
-
Monday, January 07, 2008 5:48 PM
I may be wrong, but I believe at the present time, items in a ToolBar can only be added with the XAML editor. Once added, you can edit and move them using the Collection Editor for the ToolBar.
-
Tuesday, January 08, 2008 3:27 PM
That's very simple. As you might have noticed you can place nearly everything to the toolbar to be regarded as it's item. The same is for code behind. Sample snippet for common button control
<
Window x:Class="WebBrowsingTest.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <Grid> <ToolBarTray> <ToolBar x:Name="myToolBar"> <Button>xxx</Button> <Button>yyy</Button> </ToolBar> </ToolBarTray> </Grid></
Window>If you named the toolbar you can also do it from the code behind:
myToolBar.Items.Add(
new Button() { Content = "333" });I used to store the drop downs and zooming sliders in a similar manner so there's no problems until you know the purpose of what you are doing

Guess you should play with it a bit trying to set the controls you need.
-
Tuesday, January 08, 2008 3:49 PM
Hi Denis,
Thank you for helping me. I did what you do and it's great now!
Thank you!!
-
Wednesday, June 13, 2012 7:07 PM
Hi Denis,
What if toolbar is defined in XAML as following? FC is defined in another XAML file inside <ResourceDictionary> then what do you suggest?
<Expander x:Name="myExpander1" Header="Controls" Content="{StaticResource FC}" IsExpanded="True" /
Regards,
Amit

