我在我的应用程序中有ListBox
项目数量。我使用以下代码
ListBoxItem
动画
var blinkStoryboard = new Storyboard
{
Duration = TimeSpan.FromMilliseconds(1000),
RepeatBehavior = RepeatBehavior.Forever,
};
var currentFence = GPSData.lstRouteDetail.Where(x => x.ID == stationID).FirstOrDefault();
ListBoxItem myListBoxItem = (ListBoxItem)(routeList.ItemContainerGenerator.ContainerFromIndex(stationID));//.ContainerFromIndex(i));
ContentPresenter myContentPresenter = FindVisualChild<ContentPresenter>(myListBoxItem);
DataTemplate myDataTemplate = myContentPresenter.ContentTemplate;
Ellipse target = (Ellipse)myDataTemplate.FindName("sa", myContentPresenter);
SolidColorBrush mySolidColorBrush = new SolidColorBrush();
// Describes the brush's color using RGB values.
// Each value has a range of 0-255.
mySolidColorBrush.Color = Color.FromRgb(0, 128, 0);
target.Fill = mySolidColorBrush;
var blinkAnimation = new DoubleAnimationUsingKeyFrames();
blinkAnimation.KeyFrames.Add(new DiscreteDoubleKeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0))));
blinkAnimation.KeyFrames.Add(new DiscreteDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(500))));
Storyboard.SetTarget(blinkAnimation, target);
Storyboard.SetTargetName(myListBoxItem, stationID.ToString());
Storyboard.SetTargetProperty(blinkAnimation, new PropertyPath(OpacityProperty));
blinkStoryboard.Children.Add(blinkAnimation);
blinkStoryboard.Begin();
我需要一次只动画一个项目。在我的情况下,当我添加动画到第二项时,动画不从第一项删除。
如何在动画第二项之前从上一项删除动画?