Friday, November 26, 2010

Observable collections and photo slide show in Silverlight

Recently I did a  nice photo collection slide show in Silverlight. It is really simple. Use observable collection.

I had a list of thumbnail URLs in a list generated from a web service. The image list had 10 image urls in it.

I created a second list with 3 image urls as an observable collection in the class declaration.

public ObservableCollection<String>  Thumb_list { get; set; }

Then I had XAML for holding 3 images and had a left and right arrow buttons on both sides of the images.

When they were clicked the observable collections image list was again populated with new images offset by one from the original image list. The code is given below.  Of course, you have to make sure that you are not over running the indexes.

  private void Click_Left_Arrow(object sender, RoutedEventArgs e)
{
var thumblistdetails = ((Button)sender).DataContext as client_data;
if (thumblistdetails.image_index > 0)
{
thumblistdetails. Thumb_list[0] = List_silver_data[thumblistdetails.row_index].Thumb_list[thumblistdetails.image_index - 1];
thumblistdetails. Thumb_list[1] = List _silver_data[thumblistdetails.row_index].Thumb_list[thumblistdetails.image_index];
thumblistdetails Thumb_list[2] = List_silver_data[thumblistdetails.row_index]. Thumb_list[thumblistdetails.image_index + 1];
thumblistdetails.image_index--;
}
}



This was a cool application. Shortly I will write a code project article on this.

No comments:

Post a Comment