/// <summary> /// Place a item to carousel canvas. /// </summary> /// <param name="item">The item will be placed.</param> /// <returns>The <see cref="CarouselItem"/> just placed.</returns> private CarouselItem PlaceItem(ItemSource item) { CarouselItem cItem = new CarouselItem(); cItem.Width = ItemWidth; cItem.Height = ItemHeight; cItem.Source = item.ImageSource; cItem.Tag = item; // Attach the handle cItem.MouseLeftButtonDown += new MouseButtonEventHandler(item_MouseLeftButtonDown); // Add item to carousel canvas CarouselCanvas.Children.Add(cItem); return cItem; }
/// <summary> /// Build storyboard to animate the item. /// </summary> /// <param name="name">The name of the storyboard.</param> /// <param name="from">The from angle.</param> /// <param name="to">The end angle.</param> /// <param name="duration">The duration of the animation.</param> /// <returns>The builded storyboard.</returns> //private Storyboard BuildStoryboard(CarouselItem item, double from, double to, Duration duration) //{ // Storyboard storyboard = new Storyboard(); // //this.Resources.Add(name, storyboard); // // Angle animation // DoubleAnimation doubleAnimation = new DoubleAnimation(); // doubleAnimation.From = from; // doubleAnimation.To = to; // doubleAnimation.Duration = duration; // doubleAnimation.RepeatBehavior = RepeatBehavior.Forever; // // Set storyboard target property // storyboard.Children.Add(doubleAnimation); // Storyboard.SetTarget(doubleAnimation, item); // Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Angle")); // return storyboard; //} /// <summary> /// Build storyboard to animate the item. /// </summary> /// <param name="name">The name of the storyboard.</param> /// <param name="by">The total amount by which the animation changes its starting value.</param> /// <returns>The builded storyboard.</returns> private Storyboard BuildStoryboard(CarouselItem item, double by, Duration duration) { Storyboard storyboard = new Storyboard(); //this.Resources.Add(name, storyboard); // Angle animation DoubleAnimation doubleAnimation = new DoubleAnimation(); doubleAnimation.By = by; doubleAnimation.Duration = duration; doubleAnimation.RepeatBehavior = RepeatBehavior.Forever; // Set storyboard target property storyboard.Children.Add(doubleAnimation); Storyboard.SetTarget(doubleAnimation, item); Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Angle")); return storyboard; }