Quite a few issues here:
- Your list (
ItemsControl
) accesses the images via aBinding
, but you never set the list'sDataContext
- the object which the binding system will try to get data from (in your case, theVideos
window itself). - Bindings only work on public properties, not private fields like your
images
collection. - When the
Images()
function is done loading thumbnails, the binding system needs to be notified that the bound collection (public property) has changed, either by implementingINotifyPropertyChanged
and raising thePropertyChanged
event, or by making the property aDependencyProperty
. - The way it's written now, the
Images()
function creates a collection ofImage
s, and the ItemsControl uses them as the sources for newImage
s. Using anImage
as the source of anImage
is overkill (if it even works). AnImage
happliy takes e.g. a URI as a source though, so instead of generatingImage
s in code, yourimages
collection can simply be the list oflink_thumb
urls.
I suggest you read up on data binding in WPF. There are lots of resources out there.
For this particular case though, because everything is done in your Videos
window, you could skip bindings altogether, and just force-feed the list of images into the ItemsControl
if you give it a name:
<ItemsControl Margin="72,30,76,30" x:Name="_imageList" >
...
Code-behind:
public void Images()
{
var images = new ObservableCollection<string>();
var wcf = new ServiceReferenceVideo.VideoServiceClient();
foreach (var item in wcf.GetAllVideos())
{
string link_thumb = wcf.GetThumbImage((wcf.GetVideoId(item.urlVideo)));
images.Add(link_thumb);
}
_imageList.ItemsSource = images;
}