tags:

views:

56

answers:

1

I'm trying to create a simple toolbar in WPF, but the toolbar shows up with no corresponding buttons on it, just a very thin blank white strip. Any idea what I'm doing wrong, or what the recommended procedure is? Relevant code fragments so far:

        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;
+1  A: 

Without a third child-element for the Dockpanel p, the 'sb' element will fill everything except for the area of tb. The ToolBar will autoSize (its Height) according to its contents.

I suggest adding a simple text button first, to check the overall layout:

var b2 = new Button();   
b2.Content = "B2";
tb.Items.Add(b2);

And then investigate what is wrong with the "back.png" image.

Henk Holterman
Thanks, that approach worked! Turned out for some reason the relative Uri path doesn't work, so the image has to be loaded with myImage.Source = new BitmapImage(new Uri("pack://application:,,,/back.png", UriKind.RelativeOrAbsolute));
rwallace