■ Storyboard 엘리먼트에서 실행시 TargetName 속성을 동적 사용하는 방법을 보여준다.
▶ 예제 코드 (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 |
<StackPanel Orientation="Horizontal"> <StackPanel.Resources> <Storyboard x:Name="storyboard"> <DoubleAnimation x:Name="doubleAnimation" Storyboard.TargetProperty="Opacity" AutoReverse="True" Duration="0:0:2" From="1.0" To="0.0" /> </Storyboard> </StackPanel.Resources> <Rectangle x:Name="rectangle1" Margin="3" Width="100" Height="100" Fill="Blue" MouseLeftButtonDown="rectangle_MouseLeftButtonDown" /> <Rectangle x:Name="rectangle2" Margin="3" Width="100" Height="100" Fill="Blue" MouseLeftButtonDown="rectangle_MouseLeftButtonDown" /> <Rectangle x:Name="rectangle3" Margin="3" Width="100" Height="100" Fill="Blue" MouseLeftButtonDown="rectangle_MouseLeftButtonDown" /> <Rectangle x:Name="rectangle4" Margin="3" Width="100" Height="100" Fill="Blue" MouseLeftButtonDown="rectangle_MouseLeftButtonDown" /> </StackPanel> |
▶ 예제 코드 (C#)
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 |
using System.Windows.Input; using System.Windows.Shapes; using System.Windows.Media.Animation; #region 사각형 마우스 왼쪽 버튼 DOWN시 처리하기 - rectangle_MouseLeftButtonDown(sender, e) /// <summary> /// 사각형 마우스 왼쪽 버튼 DOWN시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void rectangle_MouseLeftButtonDown(object sender, MouseEventArgs e) { this.storyboard.Stop(); Rectangle rectangle = pSender as Rectangle; this.doubleAnimation.SetValue(Storyboard.TargetNameProperty, rectangle.Name); this.storyboard.Begin(); } #endregion |