Хорошо, я понял это, и я думаю, что я также нашел хорошее решение :) ИМХО
Я в основном привязал Image.source к свойствам моего класса (теперь это расширение INotifyPropertyChanged). Но это дало мне некоторую проблему с транскрипцией между изображениями: поскольку они были загружены из Интернета, между изображениями появлялись чёрные изображения ... и только в первый раз (я зацикливаюсь на наборе из 4 изображений) похоже, что видео повторяется), потому что после этого изображения кэшируются.
Итак, что я сделал, так это кешировал изображения в первый раз, не отображая правильный элемент управления изображением, а вместо этого отображая другой элемент управления изображением (или что-то еще), который говорит пользователю «Я загружаю».
Для обработки этого сценария я создал пользовательское событие:
public delegate void FramesPrefetchedEventHanlder();
public event FramesPrefetchedEventHanlder FramesPrefetched;
Теперь давайте посмотрим на метод RetrieveImages:
private void RetrieveImages()
{
frameNumber = 0;
currentCycle = 0;
// set e very short interval, used for prefetching frames images
timer.Interval = new TimeSpan(0, 0, 0, 0, 10);
timer.Tick += (sender, e) => gotoNextImage();
// defines what is going to happen when the prefetching is done
this.FramesPrefetched += () =>
{
// hide the "wait" image and show the "movie" one
imageLoading.Opacity = 0;
image1.Opacity = 1;
// set the timer with a proper interval to render like a short movie
timer.Interval = new TimeSpan(0, 0, 0, 0, 400);
};
// when a frame is loaded in the main Image control, the timer restart
image1.ImageOpened += (s, e) =>
{
if (currentCycle <= cycles) timer.Start();
};
// start the loading (and showing) frames images process
gotoNextImage();
}
Хорошо, теперь нам нужно выполнить пошаговую загрузку изображения и сообщить, когда мы закончили фазу предварительной выборки:
private void gotoNextImage()
{
timer.Stop();
if (frameNumber < 4)
{
CurrentFrame = new System.Windows.Media.Imaging.BitmapImage(new Uri(cam.framesUrl[frameNumber]));
frameNumber++;
}
else
{
// repeat the frame's sequence for maxCycles times
if (currentCycle < maxCycles)
{
frameNumber = 0;
currentCycle++;
// after the first cycle through the frames, raise the FramesPrefetched event
if (currentCycle == 1)
{
FramesPrefetchedEventHanlder handler = FramesPrefetched;
if (handler != null) handler();
}
// step over to next frame
gotoNextImage();
}
}
}
Это прекрасно работает для меня ... но, поскольку я новичок в разработке Silverlight и Windows Phone 7, любые предложения по улучшению приветствуются.