If you want to implement such a control, its transparency will be smoothly transitioned from 0 to 1, and then smoothly transitioned from 1 to 0 (that is, the flickering effect in the dark ).
One way is to define a timer and repeatedly change its transparency.
One way is to use storyboard to achieve this flickering effect. The code is more concise and the code is as follows:
private Storyboard PrepareShowStory() { Storyboard story = new Storyboard(); DoubleAnimation animation; animation = new DoubleAnimation(); animation.From = 0; animation.To = 1; animation.Duration = new Duration(TimeSpan.FromMilliseconds(Duration)); Storyboard.SetTarget(animation, MyTestImage); Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.Opacity)")); story.Children.Add(animation); story.AutoReverse = true; story.RepeatBehavior = RepeatBehavior.Forever; return story; }
To start the animation, you can set it as follows:
m_StoryBoard = PrepareShowStory();m_StoryBoard.Begin();
To pause an animation, you can:
m_StoryBoard.Pause();
To re-run the animation, you can:
m_StoryBoard.Resume();
To end the animation, you can:
m_StoryBoard.Stop();