본문 바로가기

   
Programming/WPF

StoryBoard

반응형
Animation은 동시에 실행되지만 BeginTime은 딜레이를 주어서 실행할수 있다.

 
<Window x:Class="WPFEx.StoryBoard"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="StoryBoard" Height="300" Width="300">

      

       <Window.Triggers>

             <EventTrigger SourceName="btn1" RoutedEvent="Button.Click">

                    <BeginStoryboard>

                           <Storyboard SpeedRatio="0.1">

                                 <DoubleAnimation Storyboard.TargetName="btn1" Storyboard.TargetProperty="FontSize" By="50" Duration="0:0:0"/>

                                 <DoubleAnimation Storyboard.TargetName="btn2" Storyboard.TargetProperty="FontSize" By="50" Duration="0:0:2" BeginTime="0:0:0"/>

                           </Storyboard>

                    </BeginStoryboard>

             </EventTrigger>

       </Window.Triggers>

 

       <StackPanel HorizontalAlignment="Center">

             <Button Name="btn1" Content="버튼1" />

             <Button Name="btn2" Content="버튼2" />

       </StackPanel>

</Window>

 

 


XAML 
<Window x:Class="WPFEx.StoryBoard02"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="StoryBoard02" Height="300" Width="300">

       <Window.Resources>

            

             <!--스토리 보드를 리소스로 : 1. 객체 리소스-->

             <Storyboard x:Key="amStory" Completed="Storyboard_Completed">

                    <ColorAnimation Storyboard.TargetName="btn" Storyboard.TargetProperty="Background.Color" From="White" To="Red" Duration="0:0:2" />

             </Storyboard>

 

             <Storyboard x:Key="pmStory">

                    <ColorAnimation Storyboard.TargetName="btn" Storyboard.TargetProperty="Background.Color" From="White" To="Blue" Duration="0:0:2" />

             </Storyboard>

            

       </Window.Resources>

      

       <Grid>

            

             <Button Name="btn" Content="버튼" Width="50" Height="{Binding RelativeSource={RelativeSource Self}, Path=Width}" Background="White">

                    <Button.Triggers>

                           <EventTrigger RoutedEvent="Button.Click">

                                 <BeginStoryboard>

                                        <Storyboard>

                                              <DoubleAnimation Storyboard.TargetProperty="Width" From="50" To="250" Duration="0:0:3" />

                                        </Storyboard>

                                 </BeginStoryboard>

                           </EventTrigger>

                    </Button.Triggers>

             </Button>

            

       </Grid>

      

</Window>

 

 

C# 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Shapes;

using System.Windows.Media.Animation;

 

 

namespace WPFEx

{

       /// <summary>

       /// StoryBoard02.xaml에 대한 상호 작용 논리

       /// </summary>

       public partial class StoryBoard02 : Window

       {

             public StoryBoard02()

             {

                    InitializeComponent();

             }

 

             private void Storyboard_Completed(object sender, EventArgs e)

             {

                    string story = "";

 

                    //1. 오전? 오후?

                    if (DateTime.Now.Hour < 12)

                    {

                           story = "amStory";

                    }

                    else

                    {

                           story = "pmStory";

                    }

 

                    //2. C#에서 XAML에 등록된 리소스를 접근하는 방법

                    //2.1 누구의 리소스인지?

                    Storyboard s = (Storyboard)this.Resources[story];

 

                    //3. 스토리보드 실행

                    s.Begin();

             }

       }

}

  

 <Window x:Class="WPFEx.AnimationTotal"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="AnimationTotal" Height="300" Width="300">

      

       <StackPanel>

            

             <Button Content="시작" Width="100">

                    <Button.Triggers>

                           <EventTrigger RoutedEvent="Button.Click">

                                 <BeginStoryboard>

                                        <Storyboard>

                                             

<!--<DoubleAnimation From="0" To="360" Duration="0:0:3" RepeatBehavior="Forever" Storyboard.TargetName="rect" Storyboard.TargetProperty="RenderTransform.Angle"/>-->

<DoubleAnimation From="0" To="360" Duration="0:0:3" RepeatBehavior="Forever" Storyboard.TargetName="rTrans" Storyboard.TargetProperty="Angle"/>                   

                                        </Storyboard>

                                 </BeginStoryboard>

                           </EventTrigger>

                    </Button.Triggers> 

             </Button>

            

             <Rectangle Name="rect" Width="150" Height="150" Stroke="Black" StrokeThickness="5" Fill="Yellow" Margin="30" RenderTransformOrigin=".5,.5">

                    <Rectangle.RenderTransform>

                           <RotateTransform Angle="0" x:Name="rTrans" />

                    </Rectangle.RenderTransform>

              </Rectangle>

       </StackPanel>

      

</Window>

 

 


<Window x:Class="WPFEx.Animation14"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="Animation14" Height="300" Width="300">

    <Grid>

             <Button Content="버튼" Width="200" Height="200" FontSize="40" RenderTransformOrigin="0.5,0.5" FocusVisualStyle="{x:Null}">

                    <Button.RenderTransform>

                           <!--<RotateTransform x:Name="rTrans" />-->

                           <!--ScaleTransform : 배율-->

                           <ScaleTransform x:Name="sTrans" />

                    </Button.RenderTransform>

                    <Button.Triggers>

                           <EventTrigger RoutedEvent="Button.Click">

                                 <BeginStoryboard>

                                        <Storyboard>

<DoubleAnimation Storyboard.TargetName="sTrans" Storyboard.TargetProperty="ScaleX" From="-1" To="1" AutoReverse="True" Duration="0:0:1" RepeatBehavior="Forever" />

                                        </Storyboard>

                                 </BeginStoryboard>

                           </EventTrigger>

                    </Button.Triggers>

             </Button>

       </Grid>

</Window>

 

 


 <!--TranslateTransform : 현재 위치를 변형 => Canvas에서의 위처 변경 효과 유사-->

      

<Window x:Class="WPFEx.Animation15"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="Animation15" Height="300" Width="300">

      

       <Grid>

             <!--

                    TranslateTransform : 현재 위치를 변형

                    => Canvas에서의 위치 변경 효과 유사

             -->

             <Button Content="버튼" Width="50" Height="50" RenderTransformOrigin="0.5,0.5">

                    <Button.RenderTransform>

                           <TranslateTransform x:Name="tTrans" X="0" Y="0" />

                    </Button.RenderTransform>

                    <Button.Triggers>

                           <EventTrigger RoutedEvent="Button.Click">

                                 <BeginStoryboard>

                                        <Storyboard>

                                              <DoubleAnimation

                           Storyboard.TargetName="tTrans"

                           Storyboard.TargetProperty="X"

                           From="0" To="120" Duration="0:0:1"

                                                     />

                                        </Storyboard>

                                 </BeginStoryboard>

                           </EventTrigger>

                    </Button.Triggers>

             </Button>

       </Grid>

</Window>

 

 

 

반응형