I have a program where it gets images from website and bind it to the list. I tested the link on my browser and it's shows the image however, when I run, it showing error:
WinRT information: The value cannot be converted to type ImageSource.
I was previously worked on some projects with list view and I never got this error before.
<ListView Grid.Row="1" ItemsSource="{x:Bind AllSongs}"
Margin="50,20,50,0">
<ListView.ItemTemplate>
<DataTemplate x:DataType="data:SongList">
<StackPanel Orientation="Horizontal">
<Image Source="{x:Bind Image}"/>
<TextBlock Text="{x:Bind Name}"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
My xaml.cs code
public sealed partial class MainPage : Page
{
ObservableCollection<SongList> AllSongs;
public MainPage()
{
this.InitializeComponent();
AllSongs = new ObservableCollection<SongList>();
}
private async void searchButton_Click(object sender, RoutedEventArgs e)
{
MyProgress.IsActive = true;
MyProgress.Visibility = Visibility.Visible;
var allSongs = await SongListManager.GetSongListsAsync(singerAlbumSearchbar.Text);
foreach (var songs in allSongs)
AllSongs.Add(songs);
MyProgress.IsActive = false;
MyProgress.Visibility = Visibility.Collapsed;
}
}
And the code I use to get the links
public class SongListManager
{
public static async Task<List<SongList>> GetSongListsAsync(string SingerName)
{
var newSongList = new List<SongList>();
HttpClient client = new HttpClient();
var jsonData = await client.GetStringAsync("https://theaudiodb.com/api/v1/json/1/searchalbum.php?s=" + SingerName);
var response = JsonConvert.DeserializeObject<Rootobject>(jsonData);
for (int i = 0; i < response.album.Length; i++)
{
newSongList.Add(new SongList() { Image = response.album[i].strAlbumThumb, Name = response.album[i].strAlbum });
}
return newSongList;
}
}