Вам необходимо создать другое свойство изображения для ImageSource, как показано ниже:
private ImageSource img;
public ImageSource Img
{
get { return img; }
set
{
img = value;
OnPropertyChanged();
}
}
private UserDTO Obj;
public UserDTO obj
{
get { return Obj; }
set
{
Obj = value;
OnPropertyChanged();
}
}
Now
public Data(UserResponse result)
{
//show = test;
InitializeComponent();
obj = result.Data;
if (!string.IsNullOrEmpty(obj.avatar))
{
Img = await getImageSource(obj.avatar);
}
}
и привязать свойство Img к вашему XAML-коду, как показано ниже:
<StackLayout Padding="20, 60">
<Label Text="Id" TextColor="Red" />
<Editor BindingContext="{x:Reference Name=MyPage}" Text="{Binding obj.id}" IsReadOnly="True" />
<Label Text="First Name" TextColor="Red"/>
<Editor BindingContext="{x:Reference Name=MyPage}" Text="{Binding obj.first_name}" IsReadOnly="True"/>
<Label Text="Last Name" TextColor="Red"/>
<Editor BindingContext="{x:Reference Name=MyPage}" Text="{Binding obj.last_name}" IsReadOnly="True"/>
<Label Text="Email" TextColor="Red"/>
<Editor BindingContext="{x:Reference Name=MyPage}" Text="{Binding obj.email}" IsReadOnly="True"/>
<Editor BindingContext="{x:Reference Name=MyPage}" Text="Image" IsReadOnly="True"/>
<Image BindingContext="{x:Reference Name=MyPage}" Source="{Binding Img}" HeightRequest="100" WidthRequest="100"/>
</StackLayout>
Добавьте следующий метод для получения источника изображения:
public async Task<ImageSource> getImageSource(string url)
{
byte[] byteArray = Client.DownloadData(url);
return ImageSource.FromStream(() => new MemoryStream(byteArray));
}
Теперь получите изображение в Img
Img = await getImageSource (obj.avatar);
Вывод:
Надеюсь, это поможет вам
Спасибо