errors that cannot be read from the stream by the binding Times of the Image control
it is found that there is a problem with the picture. Refer to the detection method of using HttpWebRequest on the Internet, combined with finding that the PropertyItems of the problem picture is empty (not sure whether it can be used as a basis for judgment).
personal example:
// ;
foreach ( info in res.data)
{
if (string.IsNullOrEmpty(info.hospitalPicture))
{
continue;
}
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(info.hospitalPicture);
WebResponse response = request.GetResponse();
Image img = Image.FromStream(response.GetResponseStream());
if (img.PropertyItems.Length == 0)
{
Logger.Net.Debug($"[]{info.hospitalName}");
ShowAlert(false, "", $"{info.hospitalName} ");
info.hospitalPicture = "";
}
}
var buttons = res.data.Select(x => new HospitalButtonInfo()
{
Name = x.hospitalName,
HospitalId = x.hospitalId,
Order = x.hospitalId == FrameworkConst.HospitalId ? 1 : 2,
IsEnabled = true,
ImageSource = string.IsNullOrEmpty(x.hospitalPicture) ? ResourceEngine.GetImageResource("_House") : new BitmapImage(new Uri(x.hospitalPicture, UriKind.Absolute))
}).ToList();
Data = buttons;
construct
in addition, the error should occur after constructing the BitmapImage, not when the control binds the data, because putting the foreach section after building the buttons will still make an error, which also indicates that there is a delay in constructing the BitmapImage? That is, even if the ImageSource is reassigned later, the previous BitmapImage build will still run.