Creating a toolbar programmatically in WPF
I'm trying to create a simple toolbar in WPF, but the toolbar is showing with no corresponding buttons on it, just a very thin blank white bar. Any idea what I am doing wrong, or what is the recommended procedure? Relevant code snippets:
var tb = new ToolBar();
var b = new Button();
b.Command = comback;
Image myImage = new Image();
myImage.Source = new BitmapImage(new Uri("back.png", UriKind.Relative));
b.Content = myImage;
tb.Items.Add(b);
var p = new DockPanel();
//DockPanel.SetDock(mainmenu, Dock.Top);
DockPanel.SetDock(tb, Dock.Top);
DockPanel.SetDock(sb, Dock.Bottom);
//p.Children.Add(mainmenu);
p.Children.Add(tb);
p.Children.Add(sb);
Content = p;
+2
a source to share
1 answer
Without a third child for the Dockpanel p, the 'sb' element will fill everything except the tb area. The dashboard will automatically adjust (its height) according to its contents.
I suggest adding a simple text button first to test the overall layout:
var b2 = new Button();
b2.Content = "B2";
tb.Items.Add(b2);
And then investigate what's wrong with the "back.png" image.
+3
a source to share