user1219627
user1219627

Reputation: 787

Adding newly created image object to window

Image myImage3 = new Image();
BitmapImage bi3 = new BitmapImage();
bi3.BeginInit();
bi3.UriSource = new Uri(@"C:\Users\User\Desktop\Awesomeness\PicProgram\Program\bin\Debug\flower.png", UriKind.Relative);
bi3.EndInit();
myImage3.Stretch = Stretch.Fill;
myImage3.Source = bi3;

I was wondering how I get myImage3 added to the window.

I've tried this.content.add.myImage3 or this.add(myImage3) and other variations none seem to work.

Any suggestions?

Thanks

Upvotes: 1

Views: 90

Answers (1)

Lap
Lap

Reputation: 254

Seems like a basic wpf usage question, although doing something that is simple in xaml can get a bit complex in code behind.....

You have to add your image to some panel or content control in your window, not the window itself. So if there is a grid in your window, give the grid a name like m_grid, then do m_grid.children.add(myImage3).

Upvotes: 1

Related Questions