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 8676329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:10:03+00:00 2026-06-12T20:10:03+00:00

I have an image on my wpf page which opens an image file form

  • 0

I have an image on my wpf page which opens an image file form hard disk. The XAML for defining the image is:

  <Image  Canvas.Left="65" Canvas.Top="5" Width="510" Height="255" Source="{Binding Path=ImageFileName}"  />

I am using Caliburn Micro and ImageFileName is updated with the name of file that image control should show.

When the image is opend by image control, I need to change the file. But the file is locked by image control and I can not delete or copy any mage over it. How can I force Image to close the file after it opened it or when I need to copy another file over it?

I checked and there is no CashOptio for image so I can not use it.

  • 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-12T20:10:05+00:00Added an answer on June 12, 2026 at 8:10 pm

    You could use a binding converter like below that loads an image directly to memory cache by setting BitmapCacheOption.OnLoad. The file is loaded immediately and not locked afterwards.

    <Image Source="{Binding ...,
                    Converter={StaticResource local:StringToImageConverter}}"/>
    

    The converter:

    public class StringToImageConverter : IValueConverter
    {
        public object Convert(
            object value, Type targetType, object parameter, CultureInfo culture)
        {
            object result = null;
            var path = value as string;
    
            if (!string.IsNullOrEmpty(path))
            {
                var image = new BitmapImage();
                image.BeginInit();
                image.CacheOption = BitmapCacheOption.OnLoad;
                image.UriSource = new Uri(path);
                image.EndInit();
                result = image;
            }
    
            return result;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
    

    Even better, load the BitmapImage directly from a FileStream:

    public object Convert(
        object value, Type targetType, object parameter, CultureInfo culture)
    {
        object result = null;
        var path = value as string;
    
        if (!string.IsNullOrEmpty(path) && File.Exists(path))
        {
            using (var stream = File.OpenRead(path))
            {
                var image = new BitmapImage();
                image.BeginInit();
                image.CacheOption = BitmapCacheOption.OnLoad;
                image.StreamSource = stream;
                image.EndInit();
                result = image;
            }
        }
    
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following xaml for changing the image for WPF button when mouse
I have an image control as: <Image Height=209 HorizontalAlignment=Left Margin=66,74,0,0 Name=image1 Stretch=Fill VerticalAlignment=Top Width=200
I have an Image control on my WPF Form. How can I create a
I have an image control on a Window in my WPF project XAML: <Image
I'm putting a WPF application together in which I have an image control which
Is it possible, in WPF, to have an image on the left side of
I have an image in WPF that I would like to have display different
Possible Duplicate: WPF Image to byte[] Relative to this I have a BitmapSource image
I have an image in a C# WPF app whose build action is set
I have a 16 bit grayscale image that I want to display using WPF

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.