How to Clear an image control in WPF (C#)

Posted by antongladchenko on Stack Overflow See other posts from Stack Overflow or by antongladchenko
Published on 2010-04-13T12:30:14Z Indexed on 2010/04/13 12:32 UTC
Read the original article Hit count: 691

Filed under:
|
|
|
|

I have an image control with a source image located in my c drive. I get a message that the image is being used by another process whenever I try to delete the original image to change it with another one dynamically. How do I release the image from the image control to be able to delete it.

I tried this variants:

string path = ((BitmapImage)img.Source).UriSource.LocalPath;
img.SetValue(System.Windows.Controls.Image.SourceProperty, null);
File.Delete(path);

And:

string path = ((BitmapImage)img.Source).UriSource.LocalPath;
img.Source = null;
File.Delete(path)

But it's not work...

© Stack Overflow or respective owner

Related posts about wpf

Related posts about c#