Login
Portfolio Management & My Site Ver2.2b    RSS   RSS 2.0

   휴지통

   찾기
작성자              : Until
제목                  : [WPF] Storyboard Value 바인딩 처리 하기
내용                  :

Storyboard Value 바인딩 처리 하기

Storyboard의 DoubleAnimationUsingKeyFrames EasingDoubleKeyFrame등 애니메이션 설정시 Value을 바인딩해서 사용할때 다음과 같이 처리해야 한다.

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>


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);


        }

    }

}

BeginStoryboard호출시 Storyboard가 먼저 실행(로드)된 후 바인딩 처리가 되므로 정상적으로 Value설정이 되지 않는다.

따라서 비동기적으로 처리해야 한다.
파일첨부 첨부파일
COMMENT
파일첨부