我有一个图像控件,源图像位于我的C驱动器中。每当我尝试删除原始图像以动态更改为另一张图像时,就会收到消息说该图像正在被另一个进程使用。如何释放图像控件中的图像以便能够删除它。
我尝试了以下变体:
string path = ((BitmapImage)img.Source).UriSource.LocalPath;
img.SetValue(System.Windows.Controls.Image.SourceProperty, null);
File.Delete(path);
同时:
string path = ((BitmapImage)img.Source).UriSource.LocalPath;
img.Source = null;
File.Delete(path)
但是它不起作用...