I create a control in which the pictures will smoothly scroll.
public partial class ImagesScroll : Canvas { private ObservableCollection<BitmapImage> _images; private DispatcherTimer _dispatcherTimer; public bool AnimationVector { get; set; } public int AnimationSpeed { private get { return 0; } set { if(value > 0) _dispatcherTimer.Interval = new TimeSpan(0, 0, value); } } public bool Run { get { return _dispatcherTimer.IsEnabled; } set { if (value) _dispatcherTimer.Start(); else _dispatcherTimer.Stop(); } } public void AddImages(string[] images) { if (_images == null) _images = new ObservableCollection<BitmapImage>(); foreach(var link in images) { try { var imageSource = new BitmapImage(); imageSource.BeginInit(); imageSource.UriSource = new Uri(link); imageSource.EndInit(); _images.Add(imageSource); } catch (System.Net.WebException ex) { // log that the download was not successful } } } public ImagesScroll() { InitializeComponent(); _dispatcherTimer = new DispatcherTimer(); _dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); _dispatcherTimer.Interval = new TimeSpan(0, 0, 2); this.Refresh(); } private void dispatcherTimer_Tick(object sender, EventArgs e) { this.InvalidateVisual(); } int shift = 0; protected override void OnRender(DrawingContext dc) { if (_images != null && _images.Count < 0) dc.DrawImage(_images[0], new Rect(0, 0, 320, 320)); else { for (int j = 0; j < 5; j++) { for (int i = 0; i < 6; i++) { var x = i * 160; var y = j * 160 + shift; dc.DrawRectangle(System.Windows.Media.Brushes.Black, new System.Windows.Media.Pen(System.Windows.Media.Brushes.AliceBlue, 2), new Rect(x, y, 160, 160)); } } } shift -= 10; base.OnRender(dc); } } } But there was a problem, does not work redrawing. Another question is the correct solution to this problem, I chose?
OnRender? Is it really not enough standard animations? You yourself have chosen the most difficult path. - VladD