in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

Images not showing in StackPanel

Last post 12-21-2007 12:27 PM by C1_BernardoC. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 12-21-2007 9:13 AM

    Images not showing in StackPanel

    I've got a StackPanel inside a ScrollViewer and I'm adding an Image object between some Labels.  The Image isn't showing up.  Any ideas? 

    Filed under:
  • 12-21-2007 12:27 PM In reply to

    Re: Images not showing in StackPanel

    I tested this with the code below and it worked fine. The only idea that occurs to me is that the Image element might not be finding the actual image file. Testing this should be easy, just try creating the image and placing it directly on the page. If you can see it on the page, that means it found the image and it should work inside a StackPanel, ScrollViewer, etc.

            public void Page_Loaded(object o, EventArgs e)
            {
                // Required to initialize variables
                InitializeComponent();

                // create a StackPanel to hold some content
                StackPanel sp = new StackPanel();

                // add two checkboxes
                CheckBox cb = new CheckBox();
                cb.Text = "This checkbox is enabled";
                sp.Children.Add(cb);
                cb = new CheckBox();
                cb.Text = "This checkbox is DISABLED";
                cb.Enabled = false;
                sp.Children.Add(cb);

                // add three sets of label/image controls
                for (int i = 1; i <= 3; i++)
                {
                    Label lbl = new Label();
                    lbl.Text = "Hello friend!";
                    sp.Children.Add(lbl);

                    Image img = new Image();
                    img.Stretch = Stretch.Fill;
                    img.Width = 200;
                    img.Height = 200;
                    img.Source = new Uri(i.ToString() + ".jpg", UriKind.Relative);
                    sp.Children.Add(img);
                }

                // show the StackPanel inside a ScrollViewer
                ScrollViewer sv = new ScrollViewer();
                sv.Border.StrokeThickness = 2;
                sv.Border.Stroke = new SolidColorBrush(Colors.LightGray);
                sv.AutoSize = AutoSize.None;
                sv.Width = sv.Height = 300;
                sv.ContentElement = sp;
                Children.Add(sv);
            }

Page 1 of 1 (2 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.