none
Background image on window in WPF at runtime.

    Question

  • Hi,

    I have to display an image on the background of the window i have following code but i am getting exception"Could not find a part of the path"

    ImageBrush windowImage = new ImageBrush();

    BitmapImage bitImage = new BitmapImage(new Uri(@"..\Pics\MyImg.jpg", UriKind.RelativeOrAbsolute));

    windowImage.ImageSource = bitImage;

    this.Background = windowImage;

    Please suggest me what i need to do.

    Thanks in advance.

    Tuesday, May 03, 2011 11:05 AM

Answers

  • Say, by writing like that you are actually locate the \Pics\MyImg.jpg under the bin directory of your project. But maybe you didn't copy the image file to there. So would you please try with this path line like?

    @"..\..\Pics\test.png

    Hope this could help!

    Regards

     


    Yves Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 09, 2011 12:20 PM

All replies

  • Hi,

     

    Set your image "Build Action" to content. Initially it will be Resource.

    This should hopefully solve your problem.

    • Proposed as answer by Pritesh3 Tuesday, May 03, 2011 11:32 AM
    Tuesday, May 03, 2011 11:32 AM
  • Say, by writing like that you are actually locate the \Pics\MyImg.jpg under the bin directory of your project. But maybe you didn't copy the image file to there. So would you please try with this path line like?

    @"..\..\Pics\test.png

    Hope this could help!

    Regards

     


    Yves Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 09, 2011 12:20 PM
  •  

    We are marking this issue as "Answered". If you have any new findings or concerns, please feel free to unmark the issue. 

    Best regards


    Yves Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, May 18, 2011 7:42 AM