티스토리 뷰

c#

[wpf/c#] 페이드 인 아웃 이펙트 구현

개발자 고포고 2022. 10. 27. 16:07
반응형

[wpf/c#] 페이드 인 아웃 이펙트 구현

 

#스토리보드 생성

   <Window.Resources>
        <Storyboard x:Key="Fadein">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="MediaGrid">
                <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                <EasingDoubleKeyFrame KeyTime="0:0:1" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="Fadeout">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="MediaGrid">
                <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0">
                </EasingDoubleKeyFrame>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </Window.Resources>

 

#스토리보드 정의 후 기능 실행

 

-fadeInOut() 실행

-fadeOut 후 fadeIn 실행

 

        Storyboard fadein;
        Storyboard fadeout;
        void Init()
        {
            fadein = FindResource("Fadein") as Storyboard;
            fadeout = FindResource("Fadeout") as Storyboard;
            this.fadeout.Completed += Fadeout_Completed; //까매지는거
            fadetimer.Interval = TimeSpan.FromSeconds(2);
            fadetimer.Tick += fadetimer_Tick;
        }

        private void Fadeout_Completed(object sender, EventArgs e)
        {
            // To do
            fadetimer.Interval = TimeSpan.FromSeconds(0.25);
            fadetimer.Start();
        }

        private void fadetimer_Tick(object sender, EventArgs e)
        {
            fadetimer.Stop();
            fadein.Begin();
        }

        private void fadeInOut()
        {
            fadeout.Begin();
        }

 

#fadein #fadeout #fade #wpf #c# #페이드인아웃 #페이드 인 #페이드 아웃

반응형
댓글
반응형