在WPF中,正在被Image控件使用的图片是无法被新下载的图片替换覆盖掉或删除的。
此时删除图片或下载覆盖正在使用的图片会出现以下问题:
解决方法:把图片转换为BitmapIMAGE读成memorystream, 再进行绑定
var img = new BitmapImage(); img.BeginInit(); img.StreamSource = new MemoryStream(File.ReadAllBytes($"{System.Environment.CurrentDirectory}/test.jpg")); img.EndInit(); this.img1.Source = img;