Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9204935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:49:50+00:00 2026-06-17T23:49:50+00:00

I want to show Image in my WPF Window. I have put this code

  • 0

I want to show Image in my WPF Window.
I have put this code to do so.

<Image  x:Name="ImageControl" Stretch="Fill" Margin="2" Source="{Binding imgSource}"/>

and in code behind I have put,

    public ImageSource imgSource
    {
        get
        {
            logo = new BitmapImage();
            logo.BeginInit();
            logo.UriSource = new Uri(@"C:\MyFolder\Icon.jpg");
            logo.EndInit();                
            return logo;
        }
    }

This code shows image fine but I also should be able to change image runtime, That is, I want to replace Icon.jpg with another Image.
MyFolder is the folder path that will contain an Image “Icon.jpg” (Name would always be same).
So whenever I try to replace Icon.jpg with anyother Image, I get an error That Image file in Use

Can Anyone suggest how to overcome this issue. Please let me know if I need to clear my question.

Thanks in Anticipation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:49:52+00:00Added an answer on June 17, 2026 at 11:49 pm
    • Implement INotifyPropertyChanged in the class.

    • Change your property to a “get” “set”

    • And don’t forget to set the DataContext.

    Here is the code:

    public class MyClass : INotifyPropertyChanged
    {
        private string imagePath;
        public string ImagePath
        {
            get { return imagePath; }
            set
            {
                if (imagePath != value)
                {
                    imagePath = value;
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.BeginInit();
                    bitmapImage.UriSource = new Uri(ImagePath);
                    bitmapImage.EndInit();
                    imgSource = bitmapImage;
                }
            }
        }
    
        public BitmapImage logo;
        public ImageSource imgSource
        {
            get { return logo; }
            set
            {
                if (logo != value)
                {
                    logo = value;
                    OnPropertyChanged("imgSource");
                }
            }
        }
    
        #region INotifyPropertyChanged implementation
        public event PropertyChangedEventHandler PropertyChanged;
    
        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
                handler(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion
    }
    

    UPDATE

    BitmapImage is known to keep the file loaded when passing the path using string.
    Load with a FileStream instead. BitmapImage as on demand loading capability set by default. To foce the bitmap to load the image on EndInit you have to change the ChacheOption:

    using (FileStream stream = File.OpenRead(@"C:\MyFolder\Icon.jpg"))
    {
        logo = new BitmapImage();
        logo.BeginInit();
        logo.StreamSource = stream;
        logo.CacheOption = BitmapCacheOption.OnLoad;
        logo.EndInit();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to show image in a crystal report. Scenario is something like this.
I want to show an image view for three like on/off,if any one have
When I want to show an image I use something like this: public ActionResult
I have a site for which i want to show a image in india
I want to show image in my web page using image code. I am
I have a datagrid in my WPF app and I want to show a
I have a wpf application. I want to show two images on two buttons
I have application with WPF Ribbon and Grid. And I need to show this
I want to show the image (path of file) and below to put the
I want to show the image that mobile phone's camera its taking on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.