■ Timeline 엘리먼트의 RepeatBehavior 속성을 사용하는 방법을 보여준다.
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="800" Height="600" Title="TestProject" FontFamily="나눔고딕코딩" FontSize="16"> <Window.Resources> <DrawingBrush x:Key="GridDrawingBrushKey" Viewport="0 0 10 10" ViewportUnits="Absolute" TileMode="Tile"> <DrawingBrush.Drawing> <DrawingGroup> <DrawingGroup.Children> <GeometryDrawing Brush="#99ffffff"> <GeometryDrawing.Geometry> <RectangleGeometry Rect="0 0 1 1" /> </GeometryDrawing.Geometry> </GeometryDrawing> <GeometryDrawing Brush="#99ccccff" Geometry="M 0 0 L 1 0 1 0.1 0 0.1 Z" /> <GeometryDrawing Brush="#99ccccff" Geometry="M 0 0 L 0 1 0.1 1 0.1 0 Z" /> </DrawingGroup.Children> </DrawingGroup> </DrawingBrush.Drawing> </DrawingBrush> </Window.Resources> <Grid HorizontalAlignment="Center" VerticalAlignment="Center" Width="500"> <StackPanel Background="{StaticResource GridDrawingBrushKey}"> <TextBlock>RepeatBehavior="Forever"</TextBlock> <Rectangle Name="foreverRepeatingRectangle" HorizontalAlignment="Left" Margin="0 10 0 0" Fill="#aa3333ff" Width="50" Height="20" /> <TextBlock Margin="0 20 0 0">RepeatBehavior="00:00:04"</TextBlock> <Rectangle Name="fourSecondsRepeatingRectangle" HorizontalAlignment="Left" Margin="0 10 0 0" Width="50" Height="20" Fill="#aa3333ff" /> <TextBlock Margin="0 20 0 0">RepeatBehavior="2x"</TextBlock> <Rectangle Name="twiceRepeatingRectangle" HorizontalAlignment="Left" Margin="0 10 0 0" Fill="#aa3333ff" Width="50" Height="20" /> <TextBlock Margin="0 20 0 0">RepeatBehavior="0.5x"</TextBlock> <Rectangle Name="halfRepeatingRectangle" HorizontalAlignment="Left" Margin="0 10 0 0" Width="50" Height="20" Fill="#aa3333ff" /> <TextBlock Margin="0 20 0 0">RepeatBehavior="00:00:01"</TextBlock> <Rectangle Name="oneSecondRepeatingRectangle" HorizontalAlignment="Left" Margin="0 10 0 0" Width="50" Height="20" Fill="#aa3333ff" /> <StackPanel Orientation="Horizontal" Margin="0 20 0 0"> <Button Name="restartButton" Width="150" Height="30"> Start Animations </Button> <Button Name="stopButton" Margin="10 0 0 0" Width="70" Height="30" Background="#669900ff"> Stop </Button> <StackPanel.Triggers> <EventTrigger SourceName="restartButton" RoutedEvent="Button.Click"> <BeginStoryboard Name="beginStoryboard"> <Storyboard> <DoubleAnimation Storyboard.TargetName="foreverRepeatingRectangle" Storyboard.TargetProperty="(Rectangle.Width)" Duration="00:00:02" From="50" To="300" RepeatBehavior="Forever" /> <DoubleAnimation Storyboard.TargetName="fourSecondsRepeatingRectangle" Storyboard.TargetProperty="(Rectangle.Width)" Duration="00:00:02" From="50" To="300" RepeatBehavior="00:00:04" /> <DoubleAnimation Storyboard.TargetName="twiceRepeatingRectangle" Storyboard.TargetProperty="(Rectangle.Width)" Duration="00:00:02" From="50" To="300" RepeatBehavior="2x" /> <DoubleAnimation Storyboard.TargetName="halfRepeatingRectangle" Storyboard.TargetProperty="(Rectangle.Width)" Duration="00:00:02" From="50" To="300" RepeatBehavior="0.5x" /> <DoubleAnimation Storyboard.TargetName="oneSecondRepeatingRectangle" Storyboard.TargetProperty="(Rectangle.Width)" From="50" To="300" Duration="00:00:02" RepeatBehavior="00:00:01" /> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger SourceName="stopButton" RoutedEvent="Button.Click"> <StopStoryboard BeginStoryboardName="beginStoryboard" /> </EventTrigger> </StackPanel.Triggers> </StackPanel> </StackPanel> </Grid> </Window> |