Deleting an Image that has been used by a WPF control
- by Peter
Hi,
I would like to bind an Image to some kind of control an delete it later on.
path = @"c:\somePath\somePic.jpg"
FileInfo fi = new FileInfo(path);
Uri uri = new Uri(fi.FullName, UriKind.Absolute);
var img = new System.Windows.Controls.Image();
img.Source = new BitmapImage(uri);
Now after this code I would like to delete the file :
fi.Delete();
But I cannot do that since the image is being used now.
Between code fragment 1 en 2 what can I do to release it?
Thanks