Hello,
There are two reasons why this image cannot be loaded on the Windows platform.
- The image link you provided needs to be authenticated on Windows. This is not from a public image hosting service. This link cannot be directly parsed as an image on Windows. As a public image resource, its access should be unlimited. For example, you can replace the image link with the image resource you published in Q&A.
- Your Image control uses the
Aspect="AspectFill"
attribute and does not assign a width to the Image. In this case, the image will be stretched to the full width of the screen. You can useAspect="AspectFit"
to make the image's width automatically adjust.
In summary, you need to push the Icon image to a public image hosting service with unlimited access and set the correct attributes or width and height for the Image.
Update:
Since the success of obtaining the image link needs to be judged through Http request, you need to use ValueConverter to implement this function. Please refer to the following code example:
internal class ImgSourceConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var source = value as string;
if (source != null) {
var res = GetHttpImage(source); // The icon displayed on the page is determined by judging whether the HTTP request is successful.
if (res) {
return value;
}
}
return "dotnet_bot.png";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return true;
}
private bool GetHttpImage(string url)
{
var client = new HttpClient();
try
{
var response = client.GetAsync(url).Result;
if (response != null && response.IsSuccessStatusCode)
{
return true;
}
}
catch (Exception ex) {
return false;
}
return false;
}
}
<Image
Aspect="AspectFill"
HeightRequest="250"
WidthRequest="250"
Source="{x:Binding UrlToImage,
Converter={StaticResource ImgSourceConverter}}"
VerticalOptions="Center" />
You could refer to Binding value converters for more details.
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.