■ EventTrigger 엘리먼트를 사용해 버튼 클릭시 버튼을 흔드는 방법을 보여준다.
▶ 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 |
<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="EventTrigger 엘리먼트 : 버튼 클릭시 버튼 흔들기" FontFamily="나눔고딕코딩" FontSize="16"> <Grid> <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> <StackPanel.Resources> <Style TargetType="{x:Type Button}"> <Setter Property="HorizontalAlignment" Value="Center" /> <Setter Property="Margin" Value="10" /> <Setter Property="Padding" Value="10" /> <Setter Property="RenderTransformOrigin" Value="0.5 0.5" /> <Setter Property="RenderTransform"> <Setter.Value> <RotateTransform /> </Setter.Value> </Setter> <Style.Triggers> <EventTrigger RoutedEvent="Button.Click"> <BeginStoryboard> <Storyboard TargetProperty="RenderTransform.Angle"> <DoubleAnimation FillBehavior="Stop" AutoReverse="True" RepeatBehavior="3x" From="-5" To="5" Duration="0:0:0.05" /> </Storyboard> </BeginStoryboard> </EventTrigger> </Style.Triggers> </Style> </StackPanel.Resources> <Button>버튼 번호 1</Button> <Button>버튼 번호 2</Button> <Button>버튼 번호 3</Button> <Button>버튼 번호 4</Button> <Button>버튼 번호 5</Button> </StackPanel> </Grid> </Window> |