MainWindow.xaml
<Window.Resources> <Storyboard x:Key="xGoBike" Completed="GoBikeEndStoryboard_Completed"> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Storyboard.TargetName="xBikeLeft"> <EasingDoubleKeyFrame KeyTime="0:0:0:0" Value="-180"/> <EasingDoubleKeyFrame KeyTime="0:0:0:10" Value="{Binding BikeEndPoint}"/> </DoubleAnimationUsingKeyFrames> </Storyboard> <Storyboard x:Key="xGoBikeAfter"> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Storyboard.TargetName="xBikeLeft"> <EasingDoubleKeyFrame KeyTime="0:0:0:.5" Value="{Binding BikeEndAfterPoint}"/> </DoubleAnimationUsingKeyFrames> </Storyboard></Window.Resources>
<Window.Resources>
<Storyboard x:Key="xGoBike" Completed="GoBikeEndStoryboard_Completed">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)"
Storyboard.TargetName="xBikeLeft">
<EasingDoubleKeyFrame KeyTime="0:0:0:0" Value="-180"/>
<EasingDoubleKeyFrame KeyTime="0:0:0:10" Value="{Binding BikeEndPoint}"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="xGoBikeAfter">
<EasingDoubleKeyFrame KeyTime="0:0:0:.5" Value="{Binding BikeEndAfterPoint}"/>
</Window.Resources>
MainWindow.cs
namespace TestStoryboard{ using System; using System.Windows.Media.Animation; using System.Windows.Threading; public class MainWindow : Window { public MainWindow() { InitializeComponent(); this.DataContext = this; } public double BikeEndPoint { get { return this.ActualWidth - 170; } } public double BikeEndAfterPoint { get { return this.ActualWidth; } } private void StartAni() { Storyboard goBikeSB = this.Resources["xGoBike"] as Storyboard; Action action = () => { this.BeginStoryboard(goBikeSB); }; Dispatcher.BeginInvoke(action, DispatcherPriority.Render); } }}
namespace TestStoryboard
{
using System; using System.Windows.Media.Animation; using System.Windows.Threading;
using System;
using System.Windows.Media.Animation;
using System.Windows.Threading;
public class MainWindow : Window
public MainWindow()
InitializeComponent();
this.DataContext = this;
}
public double BikeEndPoint
get { return this.ActualWidth - 170; }
public double BikeEndAfterPoint
get { return this.ActualWidth; }
private void StartAni()
Storyboard goBikeSB = this.Resources["xGoBike"] as Storyboard;
Action action = () => { this.BeginStoryboard(goBikeSB); };
Dispatcher.BeginInvoke(action, DispatcherPriority.Render);
BeginStoryboard호출시 Storyboard가 먼저 실행(로드)된 후 바인딩 처리가 되므로 정상적으로 Value설정이 되지 않는다.