Article From:https://www.cnblogs.com/lonelyxmas/p/9689206.html
WPF: traffic signal light written in Blend

Copyright notice: This article is an original article for bloggers. It can not be reproduced without permission from bloggers. Https://blog.csdn.net/yangyisen0713/article/details/18357035

WPF interface and Behavior are very convenient to write with Blend. Here’s a traffic light I wrote. Copy to the WPF form directly after writing the code with Blend.

1.Open Blend to make a rectangle and three circles, and then fill the colors, the rectangle’s four corners programming rounded;

2.Add time animation and set the animation loop to display:

3.xamlThe code is as follows:

<Window  x:Class="wpfTraffic light.MainWindow "Xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation"Xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml"Title= "MainWindow" Height= "106.87"9 "Width=" 218.457 ">";< Window.Resources>< Storyboard x:Key= "Storyboard1" AutOReverse= "True" RepeatBehavior= "Forever" >< ColorAnimationUsingKeyFrames StoryboarD.TargetProperty= "(Shape.Fill). (SolidColorBrush.Color)" Storyboard.TargetName= "ellipse1" >< EasingColorKeyFrame KeyTime= "0:0:0.4" Value= "sc#1", 0.004391442, 0.004024717, 0.004024717 "/>< EasingColorKeyFrame KeyTime= "0:0:0.9" Value= "#FFF9FF00" />< EasingColorKeyFrame KeyTime= "0:0:1.5" Value= "sc#1", 0.004391442, 0.004024717, 0.004024717"/>< /ColorAnimationUsingKeyFrames>< ColorAnimationUsingKeyFraMES Storyboard.TargetProperty= "(Shape.Fill). (SolidColorBrush.Color)" Storyboard.TargetName= "ellipse2"">< EasingColorKeyFrame KeyTime= "0:0:0.4" Value= "#FF1B1C1B" />< EasingColorKeyFrame KeyTime= "0:0:0.9" Value= "#FF0F0E0E" />< EasingColOrKeyFrame KeyTime= "0:0:2" Value= "#FF1DFF00" />< /ColorAnimationUsingKeyFrames>< ColorAnimationUsingKeyFrames Storyboard.TargetProperty= "(Shape.Fill). (SolidColorBr)Ush.Color) "Storyboard.TargetName=" ellipse ">";< EasingColorKeyFrame KeyTime= "0:0:0.9 "Value=" #FF0F0E0E "/>";< /ColorAnimationUsingKeyFrames>< /StoryBoard>< /Window.Resources>< Window.Triggers>< EventTrigger RoutEdEvent= "FrameworkElement.Loaded" >< BeginStoryboard Storyboard= "{StaticResource SToryboard1} "/>< /EventTrigger>< /Window.Triggers>< Grid x:Name="Grid" >< Rectangle Fill= "#FF0063FF" HorizontalAlignment= "Left" Height= "65" Margin= "6".6,0,0 "Stroke=" Black "VerticalAlignment=" Top "Width=" 202 "RadiusY=" 13.394 "RadiusX=" 13.394 "/>";< Ellipse x:Name= "ellipse" Fill= "#FFFF0006" HorizontalAlignment= "Left" Height= "57" Margin= "1"1,10,0,0 "Stroke=" Black "VerticalAlignment=" Top "Width=" 56 "/>";< Ellipse x:Name= "ellipsE1 "Fill=" #FF070707 "HorizontalAlignment=" Left "Height=" 57 "Margin=" 77,10,0,0 "Stroke=" Black "Vertic"AlAlignment= "Top" Width= "56" />< Ellipse x:Name= "ellipse2" Fill= "#FF101111" HorizontalAlignment= "Left" Height= "57" Margin= "145,10,0,0" Stroke= "Black" VerticalAlignment= "Top" Width= "56" / /Gt;< /Grid>< /Window>

4.The final effect is as follows:

The following is the vertical effect picture:

Leave a Reply

Your email address will not be published. Required fields are marked *