using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace xxx
{
public partial class ImageProgress : UserControl
{
public ImageProgress()
{
InitializeComponent();
}
public BitmapImage Source
{
get { return (BitmapImage)GetValue(SourceProperty); }
set
{
SetValue(SourceProperty, value);
value.DownloadProgress += new EventHandler<DownloadProgressEventArgs>(value_DownloadProgress);
this.Image.Source = value;
this.BeginAnimation();
}
}
void value_DownloadProgress(object sender, DownloadProgressEventArgs e)
{
if (e.Progress == 100)
{
StopAnimation();
}
}
// Using a DependencyProperty as the backing store for Source. This enables animation, styling, binding, etc...
public static readonly DependencyProperty SourceProperty =
DependencyProperty.Register("Source", typeof(BitmapImage), typeof(ImageProgress), new PropertyMetadata(new PropertyChangedCallback(OnSourceChanged)));
private static void OnSourceChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
ImageProgress source = sender as ImageProgress;
if (source != null) source.Source = (BitmapImage)e.NewValue;
}
private void BeginAnimation()
{
this.Buffer.IsBusy = true;
}
private void StopAnimation()
{
this.Buffer.IsBusy = false;
this.Buffer.Visibility = Visibility.Collapsed;
}
}
}