Quantcast
Channel: VBForums - WPF, WCF, WF
Viewing all articles
Browse latest Browse all 256

Trying to set button image programmatically

$
0
0
I've got this code that creates a list of buttons to put into a toolbar strip.

I am putting a StackPanel in for the Content of the buttons - and I am seeing the TEXTBLOCK but not the image.

Any ideas why this might be?

Code:

            List<Button> list = new List<Button>();
            list.Clear();
            Button ib = new Button();
            ib.Style = (Style)FindResource("OptionButtonStyle");
            ib.Tag = "1";
            ib.Background = buttonOff;

            StackPanel sp = new StackPanel();
            sp.Orientation = Orientation.Horizontal;
            System.Windows.Controls.Image img = new System.Windows.Controls.Image();
            img.Height = 16;
            img.Width = 16;
            img.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            img.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
            img.Source = (ImageSource)FindResource("ExplorerViewImage");
            sp.Children.Add(img);
            TextBlock tb = new TextBlock();
            tb.Text = "Explorer View";
            sp.Children.Add(tb);

            ib.Content = sp; // "Explorer View";
            ib.ToolTip = "Show Explorer View";
            list.Add(ib);


Viewing all articles
Browse latest Browse all 256

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>