locked
Insert an image to Window.xaml programmatically RRS feed

  • Question

  •  Can somebody show me how to insert an image on an Expression Blend Window programmatically?

     

    Here is exactly what I am trying to do:

    I created a project and added 10 images into my project.

    I would like to modify Window1.xaml.cs code to insert an image on Window1.xaml

     

    Any hints will be appreciated!

     

    Thanks!

    Friday, May 9, 2008 5:57 PM

Answers

  •  

    Image imgImage = new Image();
    BitmapImage bmpImage = new BitmapImage(new Uri("/ImagesFolder/MyImage.png", UriKind.Relative));
    imgImage.Source = bmpImage;

    Then just add the imgImage object to whatever Grid, StackPanel, Button, etc. you want to.

    Monday, May 12, 2008 3:32 PM

All replies

  • When you say insert an image in Window1.xaml, I am assuming that you have an Image control and you want to assign image to this control via code behind.

    Check here for a sample where i have shown various ways of binding to image control - http://infosysblogs.com/microsoft/2008/04/wpf_binding_to_image_control.html
    MVP Client App
    Sunday, May 11, 2008 4:47 AM
  • Howdy,

    Select your image in the Project Panel Files category, right click and select Insert.

    Cheers
    Learn Expression Blend at learnexpressionstudio.com
    • Proposed as answer by Weavyk Tuesday, September 18, 2012 10:44 PM
    Monday, May 12, 2008 2:13 PM
    Moderator
  •  

    Image imgImage = new Image();
    BitmapImage bmpImage = new BitmapImage(new Uri("/ImagesFolder/MyImage.png", UriKind.Relative));
    imgImage.Source = bmpImage;

    Then just add the imgImage object to whatever Grid, StackPanel, Button, etc. you want to.

    Monday, May 12, 2008 3:32 PM
  • This is what I was looking for thank you!
    Monday, May 19, 2008 10:05 PM