This project is read-only.

Load data dynamically with custom data provider

Nov 29, 2010 at 4:33 PM

I am trying to load album data dynamically from an object model. Unfortunately, I haven't determined how to properly trigger the SlideHandler class's ToSlideFinishedLoading event handler when I have finished loading the album.

The only way I have figured out how to do this is by creating a dummy instance of a WebClient object and wiring up a DownloadStringCompleted event handler. Although the following code does work, there has got to be a better solution. Any ideas?

Note: I have simplified the code below.


using System;
using System.Collections.Generic;
using System.Net;

namespace Vertigo.SlideShow
	public class TestDataProvider : IDataProvider
		public event EventHandler DataFinishedLoading;

        	public TestDataProvider(Dictionary<string, Dictionary<string, string>> initParams)
            		LoadPictureData();//TODO:Load from object model

        	public void LoadPictureData()
            		Data.StartAlbumIndex = 0;
            		Data.Albums = GetPictureAlbums("Test", new Uri("", UriKind.RelativeOrAbsolute));
            		WebClient client = new WebClient();
            		client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
            		client.DownloadStringAsync(new Uri("", UriKind.RelativeOrAbsolute));

        	void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
            		DataFinishedLoading(this, EventArgs.Empty);

        	private Album[] GetPictureAlbums(string text, Uri imageUrl)
            		List<Album> albums = new List<Album>();
            		Album a = new Album() 
                		Title = text, Description = text, Thumbnail = imageUrl 
            		Slide s = new Slide()
                		Description = text, Link = imageUrl, Preview = imageUrl,
                		Source = imageUrl, Thumbnail = imageUrl, Title = text,
                		Transition = Data.FALLBACK_TRANSITION
            		List<Slide> slides = new List<Slide>();
            		a.Slides = slides.ToArray();
            		return albums.ToArray();



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <title>Slide.Show 2 | Flickr Sample</title>
    <link type="text/css" rel="stylesheet" href="../Default.css" />
<body class="light">
    <object type="application/x-silverlight-2" data="data:application/x-silverlight-2,"
        width="640" height="480">
        <param name="background" value="#fff" />
        <param name="source" value="../ClientBin/Vertigo.SlideShow.xap" />
        <param name="initParams" value="ConfigurationProvider=SimpleTheme,DataProvider=TestDataProvider;PictureLibraryName=SlideShow" />
        <a href="" style="text-decoration: none;">
            <img src="" alt="Get Microsoft Silverlight"
                style="border-style: none" />