/// <summary> /// Create and initialize a new PublicationCanvas /// </summary> /// <param name="pubs">The publications to display on the screen</param> /// <param name="height">The height of the canvas</param> public PublicationCanvas(Publication[] pubs, double height) { // map Image objects to Publications publications = pubs.ToDictionary( p => new Image() { Source = p.CoverImage, Height = height, RenderTransform = new TranslateTransform(), }, p => p ); images = publications.Keys.ToArray(); positions = new double[images.Length]; // shift entire display 500px left RenderTransform = new TranslateTransform() { X = RENDER_TRANSFORM }; // initially layout images tileWidth = 0; for (int i = 0; i < images.Length; i++) { var image = images[i]; positions[i] = tileWidth; Children.Add(image); image.StylusSystemGesture += ImageTapped; tileWidth += (int)((image.Height / image.Source.Height) * image.Source.Width); } // allow multitouch manipulation IsManipulationEnabled = true; ManipulationStarting += BeginManipulation; ManipulationDelta += HandleManipulation; ManipulationInertiaStarting += BeginInertia; ManipulationCompleted += EndManipulation; // register UI scroll at 60fps timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1.0 / 60.0) }; timer.Tick += delegate { ScrollImagesBy(RESTING_VELOCITY); }; Loaded += delegate { timer.Start(); }; }