'프로그래밍/WPF'에 해당되는 글 13건

제목 날짜
  • WPF XAML 을 C# Code로, 애니메이션, 스토리보드 2012.03.22
  • Animation(복합 움직임 다양한 움직임), Path 2012.03.21
  • WPF 스타일 내부 트리거, 변형객체 애니메이션 2012.03.21
  • StoryBoard 2012.03.20
  • Animation(2) 2012.03.20
  • DataBinding, ImageViewer 2012.03.19
  • Style, Transform, LayOutTransForm, Template, Trigger(2) 2012.03.19
  • Code, Greed, Resource 2012.03.16
  • StackPanel, ScrollViewer, WARPPanelXAML, Grid XAML, UniformGrid, Canvas, DockPanel 2012.03.16
  • WPF 애니메이션 2012.02.02

WPF XAML 을 C# Code로, 애니메이션, 스토리보드

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;

 

namespace WPFEx

{

       /// <summary>

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

       /// </summary>

       public partial class Code01 : Window

       {

             public Code01()

             {

                    InitializeComponent();

             }

 

             private void Window_Loaded(object sender, RoutedEventArgs e)

             {

                    M1();

                    //M2();

 

             }

 

             private void M1()

             {

                    Button btn = new Button();

                    btn.Content = "버튼";

                    btn.Width = 100;

                    btn.Height = 100;

                    btn.RenderTransformOrigin = new Point(0.5, 0.5);

 

                    //Transform : 부모이다(업캐스팅이 가능하도록 부모타입을 만들어 놓았다.)

                    RotateTransform rTrans = new RotateTransform();

                    rTrans.Angle = 30;

 

                    btn.RenderTransform = rTrans;

 

                    grid1.Children.Add(btn);

             }

 

             private void M2()

             {

                    Button btn = new Button();

                    btn.Content = "버튼";

                    btn.Width = 100;

                    btn.Height = 100;

                    btn.RenderTransformOrigin = new Point(0.5, 0.5);

 

                    //1. 회전

                    RotateTransform rTrans = new RotateTransform();

                    rTrans.Angle = 30;

 

 

                    //2. 스케일

                    ScaleTransform sTrans = new ScaleTransform();

                    sTrans.ScaleX = 2;

 

                    //TransformGroup

                    TransformGroup group = new TransformGroup();

                    group.Children.Add(rTrans);

                    group.Children.Add(sTrans);

 

                    btn.RenderTransform = group;//**

 

                    grid1.Children.Add(btn);

             }

 

       }

}

 

 

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>

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

       /// </summary>

       public partial class Code02 : Window

       {

             public Code02()

             {

                    InitializeComponent();

             }

 

             private void btn_Click(object sender, RoutedEventArgs e)

             {

                    //C#에서 애니메이션을 생성 -> 실행

                    //1. 2개 이상의 애니메이션을 동시에 제어를 하는 경우

                    // -> 스토리보드가 필요

                    //2. 1개의 애니메이션을 제어하는 경우

                    // -> C#에서는 스토리보드가 필요X

 

                    //버튼은 Width 100 -> 250

 

                    //1. 애니메이션 객체를 생성

                   

                    DoubleAnimation da = new DoubleAnimation();

                    da.From = 100;

                    da.To = 250;

                    da.Duration = new Duration(TimeSpan.FromSeconds(1));

                    //da.RepeatBehavior = new RepeatBehavior(3);

                    da.RepeatBehavior = RepeatBehavior.Forever;

                    da.AutoReverse = true;

                    da.AccelerationRatio = 1;

 

                    //2. 실행 -> ? da가 누구의 어떤 속성을 건드려야 함?

                    //애니메이션의 대상이 되는 객체를 찾아가 객체.BeginAnimation()호출을 해야한다.

                    //의존속성 Button.WidthProperty

                    btn.BeginAnimation(Button.WidthProperty, da);

 

             }

       }

}

 

 


XAML 

<Window x:Class="WPFEx.Code03"

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

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

        Title="Code03" Height="300" Width="300">

 

       <Window.Resources>

             <Style TargetType="{x:Type Button}">

                    <Setter Property="Width" Value="50" />

                    <Setter Property="Height" Value="0" />

                    <Setter Property="Margin" Value="3" />

                    <Setter Property="VerticalAlignment" Value="Top" />

                    <Setter Property="VerticalAlignment" Value="Bottom" />

             </Style>

       </Window.Resources>

 

       <StackPanel Name="stack" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom">

             <Button Content="국어" Name="btnKor" />

             <Button Content="영어" Name="btnEng" />

             <Button Content="수학" Name="btnMath" />

             <Button Content="성적확인" Width="60" Height="30" Click="Button_Click" />

       </StackPanel>

 

</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.IO;

using System.Windows.Media.Animation;//**

 

namespace WPFEx

{

       /// <summary>

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

       /// </summary>

       public partial class Code03 : Window

       {

             public Code03()

             {

                    InitializeComponent();

             }

 

             private void Button_Click(object sender, RoutedEventArgs e)

             {

                    //1. 파일읽기(ANSI)

                    StreamReader reader = new StreamReader(@"F:\MS닷넷(KH)\WPF\WPFEx\WPFEx\bin\Debug\data.txt", Encoding.Default);

 

                    //2. 버튼의 집합

                    List<Button> btnList = new List<Button>();

                    btnList.Add(btnKor);

                    btnList.Add(btnEng);

                    btnList.Add(btnMath);

 

 

                    //3. 성적 읽기

                    string txt = "";

                    int index = 0;

 

                    while ((txt = reader.ReadLine()) != null)

                    {

                           //MessageBox.Show(txt);

                           double score = double.Parse(txt);

                           btnList[index].Height = score * 2.5;

 

                           //4. 읽어온 성적을 가지고 DoubleAnimation생성

                           DoubleAnimation da = new DoubleAnimation();

 

                           da.From = 0;

                           da.To = score * 2.5;

                           da.Duration = new Duration(TimeSpan.FromSeconds(1));

 

                           //5. 애니메이션 실행

                           btnList[index].BeginAnimation(Button.HeightProperty, da);

 

                           index++;

 

 

                    }

 

             }

       }

}

 

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

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

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

        Title="Code04" Height="300" Width="300">

      

       <Window.Resources>

             <Style TargetType="{x:Type TextBlock}">

                    <Setter Property="FontSize" Value="50" />

             </Style>                     

       </Window.Resources>

      

      

       <Button Name="btn" Width="200" Height="200" Click="btn_Click">

             <UniformGrid>

                    <TextBlock Text="" />

                    <TextBlock Text="▲" />

                    <TextBlock Text="" />

                    <TextBlock Text="◀" />

                    <TextBlock Text="" />

                    <TextBlock Text="▶" />

                    <TextBlock Text="" />

                    <TextBlock Text="▼" />

                    <TextBlock Text="" />

             </UniformGrid>

       </Button>

      

</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.IO;

using System.Windows.Media.Animation;//**

 

namespace WPFEx

{

       /// <summary>

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

       /// </summary>

       public partial class Code04 : Window

       {

             public Code04()

             {

                    InitializeComponent();

             }

 

             private void btn_Click(object sender, RoutedEventArgs e)

             {

                    Random rnd = new Random();

                    RotateTransform rt = new RotateTransform();

                    btn.RenderTransformOrigin = new Point(0.5, 0.5);

 

                    btn.RenderTransform = rt;

 

                    //원하는 각도

                    //rt.Angle = 50;

 

                    //애니메이션

                    DoubleAnimation da = new DoubleAnimation();

                    //da.From = 0;

                    //da.To = rnd.Next(0, 1000);

                    da.By = rnd.Next(0, 1000);

                    da.Duration = new Duration(TimeSpan.FromSeconds(rnd.Next(1, 10)));

 

                    //실행(**)

                    rt.BeginAnimation(RotateTransform.AngleProperty, da);

             }

       }

}

 



같은 형태의 디자인에서 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.IO;

using System.Windows.Media.Animation;//**

 

namespace WPFEx

{

       /// <summary>

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

       /// </summary>

       public partial class Code04 : Window

       {

             public Code04()

             {

                    InitializeComponent();

             }

 

             private void btn_Click(object sender, RoutedEventArgs e)

             {

                    //1. 트랜스폼 생성

                    RotateTransform rt = new RotateTransform();

                    btn.RenderTransformOrigin = new Point(0.5, 0.5);

                    btn.RenderTransform = rt;

 

                    //2. 스토리보드 생성<Storyboard>

                    Storyboard story = new Storyboard();

 

                    //3. 애니메이션 생성 <DoubleAnmation>

                    DoubleAnimation da = new DoubleAnimation();

                    da.From = 0;

                    da.To = 3600;

                    da.Duration = new Duration(TimeSpan.FromSeconds(2));

 

                    //4. 스토리보드의 자식 -> 애니메이션

                    story.Children.Add(da);//여러개 더추가

 

                    //5. Storyboard.TargetName = "btn"

                    //   Storyboard.TargetProperty = "RenderTransform.Angle"

                    Storyboard.SetTargetName(da, btn.Name);

                    Storyboard.SetTargetProperty(da, new PropertyPath("RenderTransform.Angle"));

 

                    //6. <BeginStoryboard>

                    //어떤 컨테이너 안에 있는 컨트롤이냐?

                    story.Begin(this);

             }

       }

}

 

 


XAML 

<Window x:Class="WPFEx.Code05"

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

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

        Title="Code05" Height="650" Width="700">

 

       <Canvas>

             <TextBlock Text="▼" FontSize="30" Canvas.Left="340" Canvas.Top="10" Foreground="Gold" />

             <Image Source="F:\MS닷넷(KH)\WPF\WPFEx\WPFEx\bin\Debug\images\One.gif" Width="468" Height="468" Canvas.Left="116" Canvas.Top="80" Name="one" RenderTransformOrigin="0.5,0.5" MouseDown="one_MouseDown">

 

                    <Image.RenderTransform>

                           <RotateTransform />

                    </Image.RenderTransform>

 

             </Image>

       </Canvas>

 

</Window>

 

 

<Window x:Class="WPFEx.Code05"

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




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;

using System.Windows.Media.Imaging;

using System.Windows.Shapes;

 

namespace WPFEx

{

       /// <summary>

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

       /// </summary>

       public partial class Code05 : Window

       {

             public Code05()

             {

                    InitializeComponent();

             }

 

             private void one_MouseDown(object sender, MouseButtonEventArgs e)

             {

                    Random rnd = new Random(DateTime.Now.Millisecond);

 

                    Storyboard story = new Storyboard();

                    DoubleAnimation da = new DoubleAnimation();

                    da.From = 0;

                    da.To = rnd.Next(10000, 50000);

                    da.Duration = new Duration(TimeSpan.FromMilliseconds((double)da.To / 5.0D));

                    da.DecelerationRatio = 0.8;

                    story.Children.Add(da);

 

                    Storyboard.SetTargetName(da, one.Name);

                    Storyboard.SetTargetProperty(da, new PropertyPath("RenderTransform.Angle"));

 

                    story.Completed += new EventHandler(story_Completed);

                    story.Begin(this);

 

                   

             }

 

             void story_Completed(object sender, EventArgs e)

             {

                    //회전각? -> 선택된 누가?

                    MessageBox.Show("선택");

             }

       }

}

 

  


XAML 

<Window x:Class="WPFEx.Code06"

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

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

        Title="Code06" Height="300" Width="800" Loaded="Window_Loaded">

      

       <Window.Resources>

             <Storyboard x:Key="story">

                    <DoubleAnimation />

             </Storyboard>

       </Window.Resources>

      

    <Grid>

             <Grid.RowDefinitions>

                    <RowDefinition Height="230" />

                    <RowDefinition Height="*" />

             </Grid.RowDefinitions>

             <Grid.Children>

                    <Canvas Name="canvas1">

                          

                    </Canvas>

                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Row="1">

                           <Button Content="Left" Width="100" Height="30" Click="Button_Click" />

                           <Button Content="Right" Width="100" Height="30" Click="Button_Click" />

                    </StackPanel>

             </Grid.Children>

       </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>

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

       /// </summary>

       public partial class Code06 : Window

       {

             public Code06()

             {

                    InitializeComponent();

             }

 

             private void Window_Loaded(object sender, RoutedEventArgs e)

             {

                    //버튼(이미지) 여러개 생성 -> 캔버스

                    double left = -770;

 

                    for (int i = 0; i < 20; i++)

                    {

                           Button btn = new Button();

                           btn.Width = 100;

                           btn.Height = 200;

 

                           Canvas.SetLeft(btn, left);

                           Canvas.SetTop(btn, 15);

 

                           left += 110;

 

                           //애니메이션을 위한 추가 작업(*****)

                           //동적으로 애니메이션을 적용할때 btn.RegisterName(btn.Name, btn); 등록과정을 거쳐야지만 애니메이션에서 인식할수 있다.

                          

                           btn.Name = "btn" + i;

 

                           canvas1.Children.Add(btn);

                          

                           //화면에 추가가 된 후에 가능!!!

                           btn.RegisterName(btn.Name, btn);

 

 

                          

                    }

 

 

             }

 

             private void Button_Click(object sender, RoutedEventArgs e)

             {

                    //어느 버튼?

                    Button btn = e.Source as Button;

 

                    //이동 수치

                    double move = 660;

 

                    if (btn.Content.ToString() == "Left")

                           //MessageBox.Show("왼쪽");

                           move *= -1;

 

                    //버튼 -> 애니메이션(DoubleAnimation) -> 이동(Canva.Left)

                    //1. Canvas자체를 움직이기

                    //2. 버튼x20개를 움직이기

 

                    for (int i = 0; i < canvas1.Children.Count; i++)

                    {

                           Button b = canvas1.Children[i] as Button;

 

                           //Storyboard story = new Storyboard();

                           //DoubleAnimation da = new DoubleAnimation();

 

                           Storyboard story = this.Resources["story"] as Storyboard;

                           DoubleAnimation da = story.Children[0] as DoubleAnimation;

 

                           da.By = move;//660? ~ -660?

                           da.Duration = new Duration(TimeSpan.FromSeconds(3));

                           da.RepeatBehavior = RepeatBehavior.Forever;

 

                           Storyboard.SetTargetName(da, b.Name);

                          Storyboard.SetTargetProperty(da, new PropertyPath("(Canvas.Left)"));

 

                           story.Begin(this);

                    }

             }

       }

}

 

 


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

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

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

        Title="Code09" Height="600" Width="800" Loaded="Window_Loaded">

      

       <ListBox Name="listBox1" ScrollViewer.HorizontalScrollBarVisibility="Disabled" VerticalAlignment="Top">

             <ListBox.ItemsPanel>

                    <ItemsPanelTemplate>

                           <WrapPanel />

                    </ItemsPanelTemplate>

             </ListBox.ItemsPanel>

       </ListBox>

</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>

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

       /// </summary>

       public partial class Code09 : Window

       {

 

             private Button oldBtn;

 

             public Code09()

             {

                    InitializeComponent();

             }

 

             private void Window_Loaded(object sender, RoutedEventArgs e)

             {

                    for (int i = 0; i < 100; i++)

                    {

                           Button btn = new Button();

                           btn.Content = i.ToString();

                           btn.Width = 100;

                           btn.Height = 20;

                           btn.Margin = new Thickness(4);

                           btn.VerticalAlignment = VerticalAlignment.Top;

                           btn.Click += new RoutedEventHandler(btn_Click);

                           listBox1.Items.Add(btn);

                    }

             }

 

             void btn_Click(object sender, RoutedEventArgs e)

             {

                    //1개의 버튼을 클릭

                    Button btn = e.Source as Button;

 

                    //이전에 눌렸떤 버튼이 있는지?

                    if (this.oldBtn != null && btn != this.oldBtn)

                    {

                           if (this.oldBtn.Height != 20)

                           {

                                 DoubleAnimation da2 = new DoubleAnimation();

                                 da2.From = 150;

                                 da2.To = 20;

                                 da2.Duration = new Duration(TimeSpan.FromSeconds(0.5));

                                

                                 this.oldBtn.BeginAnimation(Button.HeightProperty, da2);

                           }

                    }

                   

 

                    DoubleAnimation da = new DoubleAnimation();

 

                    if (btn.Height == 20)

                    {

                           da.From = 20;

                           da.To = 150;

                           //da.By = 130;

                    }

                    else

                    {

                           da.From = 150;

                           da.To = 20;

                           //da.By = -130;

                    }

 

                    da.Duration = new Duration(TimeSpan.FromSeconds(0.1));

                    btn.BeginAnimation(Button.HeightProperty, da);

 

                    this.oldBtn = btn; //지금 누른 버튼

             }

       }

}

 

 




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

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

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

        Title="Code08" Height="500" Width="800">

      

       <DockPanel>

             <StackPanel Orientation="Horizontal" Height="30" DockPanel.Dock="Bottom" HorizontalAlignment="Center" Margin="5">

                    <Button Width="100" Content="지우기" Click="Button_Click" />

                    <Button Width="100" Content="저장하기" Click="Button_Click_1" />

                    <Button Width="100" Content="블러오기" Click="Button_Click_2" />

             </StackPanel>

             <InkCanvas Name="ink" />

       </DockPanel>

      

</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.IO;

using System.Windows.Markup;

using System.Windows.Ink;

using Microsoft.Win32;

 

namespace WPFEx

{

       /// <summary>

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

       /// </summary>

       public partial class Code08 : Window

       {

             public Code08()

             {

                    InitializeComponent();

             }

 

             private void Button_Click(object sender, RoutedEventArgs e)

             {

                    //지우기

                    ink.Strokes.Clear();

             }

 

             private void Button_Click_1(object sender, RoutedEventArgs e)

             {

                    //저장하기(*.xaml)

                    //OS의 대화상자를 가져와서 사용

                    SaveFileDialog save = new SaveFileDialog();

                    save.Filter = "잉크파일|*.ink";

 

                    if ((bool)save.ShowDialog() == true)

                    {

                           //this.Title = save.FileName;

                           File.WriteAllText(save.FileName, XamlWriter.Save(ink.Strokes));

                    }

 

             }

 

             private void Button_Click_2(object sender, RoutedEventArgs e)

             {

                    //불러오기

                    OpenFileDialog open = new OpenFileDialog();

                    open.Filter = "잉크파일|*.ink";

 

                    if ((bool)open.ShowDialog() == true)

                    {

                           ink.Strokes = (StrokeCollection)XamlReader.Load(File.OpenRead(open.FileName));

                    }

             }

       }

}

 

       

 

 

저작자표시

트랙백

※ 스팸 트랙백 차단중 ...{ ? }

Animation(복합 움직임 다양한 움직임), Path

<Window x:Class="WPFEx.Animation20"

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

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

        Title="Animation20" Height="300" Width="800">

       <!--

             애니메이션 객체(Timeline)

             1. DoubleAnimation : 값 => 값(등속, 가속, 감속)

             2. DoubleAnimationUsingKeyFrames : 구간별 값의 변화

             3. DoubleAnimationUsingPath : Path값에 값의 변화

       -->

       <Canvas>

             <Rectangle Width="30" Height="30" Fill="Red">

                    <Rectangle.Triggers>

                           <EventTrigger RoutedEvent="Rectangle.MouseDown">

                                 <BeginStoryboard>

                                        <Storyboard>

<DoubleAnimation Storyboard.TargetProperty="(Canvas.Left)" From="0" To="760" Duration="0:0:10" RepeatBehavior="Forever" AutoReverse="True" />

<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Canvas.Top)" Duration="0:0:2" RepeatBehavior="Forever" AutoReverse="True">

                                                     <LinearDoubleKeyFrame KeyTime="0:0:0" Value="0" />

                                                     <LinearDoubleKeyFrame KeyTime="0:0:0.5" Value="50" />

                                                     <LinearDoubleKeyFrame KeyTime="0:0:1" Value="245" />

                                                     <LinearDoubleKeyFrame KeyTime="0:0:1.5" Value="50" />

                                                     <LinearDoubleKeyFrame KeyTime="0:0:2.0" Value="0" />

                                              </DoubleAnimationUsingKeyFrames>

                                        </Storyboard>

                                 </BeginStoryboard>

                           </EventTrigger>

                    </Rectangle.Triggers>

             </Rectangle>

       </Canvas>

      

</Window>

 

 

 <Window x:Class="WPFEx.Animation21"

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

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

        Title="Animation21" Height="300" Width="300">

       <Window.Resources>

             <PathGeometry x:Key="path1" Figures="M 0, 30 A 30,30 180 0 1 60, 30 30,30 180 0 1 0 ,30" />

       </Window.Resources>

       <Canvas>

             <!--

                    패스 : 좌표의 집합

                    => 직선, 도형, 곡선 등

             -->

             <Path Stroke="Yellow" StrokeThickness="5" Data="{StaticResource path1}">

                    <Path.RenderTransform>

                           <TranslateTransform X="100" Y="150" />

                    </Path.RenderTransform>

             </Path>

 

             <Path Stroke="Red" StrokeThickness="2" Data="{StaticResource path1}" />

       </Canvas>

</Window>

 

 Path = 포인터 배열 첫번쨰 값을 x좌표에 대입 두번째 점 가져오서 x좌표에 대입 모든 점을 연결해주는 속성은 : DoubleAnimationUsingPath

[##_http://zzarungna.tistory.com/script/powerEditor/pages/1C%7Ccfile25.uf@2062893C4F697B6219140E.png%7Cwidth=%22733%22%20height=%22442%22%20alt=%22%22%20filename=%22K-14.png%22%20filemime=%22image/jpeg%22%7C_##]

[##_http://zzarungna.tistory.com/script/powerEditor/pages/1C%7Ccfile25.uf@1862893C4F697B621A5237.png%7Cwidth=%22733%22%20height=%22442%22%20alt=%22%22%20filename=%22K-15.png%22%20filemime=%22image/jpeg%22%7C_##]


<Window x:Class="WPFEx.Animation23"

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

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

        Title="Animation23" Height="800" Width="500">

 

       <Window.Resources>

             <PathGeometry x:Key="path1" Figures="M30,53 C35.136359,44.211119 27.42993,46.428028 41,41 46.957307,38.617077 51.938414,36.65316 58,35 68.685001,32.085909 74.632603,30.11366 85,39 109.06847,59.630121 110.36418,59.674628 79,100 68.767747,113.15575 60.394744,128.00657 50,141 45.159602,147.0505 43,150.49029 43,159 43,164.96601 42.557929,166.21623 47,171 56.731964,181.48058 70.575944,174.35759&#xd;&#xa;87,176 112.43744,178.54374 129.75155,182.46817 155,173 179.85091,163.68091 203.18153,151 231,151 252.63423,151 261.64783,132.83045 266,172 268.26779,192.41014 267.27129,204.42019 254,223 235.94141,248.28203 215.66829,267.3322 189,286 173.8926,296.57518 147.37162,288.74324 162,318 172.35952,338.71904 170.28172,333 199,333 206.32772,333&#xd;&#xa;222.13284,344.43358 195,358 183.36839,363.8158 180.9794,364 168,364 158.76567,364 158.44383,370.66295 156,356 151.60796,329.64777 179.3151,323.64041 223,320 254.2845,317.39296 257.11318,312.00466 274,350 290.88418,387.98941 228.39953,413 150,413 129.89716,413 103.57746,425.78873 84,416 58.462608,403.2313 58.894869,375.63079 65,339&#xd;&#xa;70.324615,307.05231 88.551803,295.04016 115,273 151.16167,242.86527 196.05385,209.42596 224,171 235.58592,155.06936 259.76929,150.50551 216,138 198.24002,132.92572 182.20395,123.5921 169,150 155.98512,176.02976 143.51815,187.62119 191,214 224.43195,232.57331 232.06519,231.20926 274,205 292.87617,193.20239 312.2373,182.73161 323,163 332.44044,145.69252 338,134.90289&#xd;&#xa;338,114 338,103.72165 321.93013,76.559959 301,83 286.93839,87.326648 284,87.891629 284,107 284,135.00136 289.3678,145.01599 335,147 416.51143,150.54398 471.25104,107.87448 547,70 499.92255,70 483.73989,82.612715 439,102 405.7629,116.40275 372.40553,124.59447 346,151 424.9484,151 496.69256,136.81394 575,124 604.7982,119.12393&#xd;&#xa;644.93289,119.55033 671,100 597.33099,100 566.8559,130.21383 501,168 475.4493,182.66024 436.73208,190.26792 416,211 453.03183,211 483.8769,197.9915 520,188 550.11972,179.66901 585.81699,175.0915 614,161 613,161 611.99251,160.87782 611,161 604.17964,161.83962 597.61158,164.12672 591,166 517.97862,186.68939 440.24204,206.49267 368,230&#xd;&#xa;347.45805,236.68429 310.94261,249.05739 294,266 313.96714,266 334.05772,266.90647 354,266 369.0409,265.31632 390.03128,258.53692 403,255 452.17942,241.58743 509.99504,234.80198 557,216 495.79586,216 440.35888,232.54704 382,252 418.89427,252 455.50785,247.96192 492,240 532.84163,231.0891 576.7259,212 619,212 607.52481,200.52481 522.84878,261.23966&#xd;&#xa;505,269 485.48262,277.48582 469.83277,280.90785 453,294 446.92118,298.72797 441.45616,300.26303 440,309 438.50996,317.94024 498.54779,320.25137 512,319 550.52333,315.41643 589.85998,303.33392 625,285 632.52468,281.07408 639.10448,281.13431 642,271 643.85022,264.52425 641.73106,264.92144 627,263 575.77781,256.31885 544.23884,265.61871 495,288 477.48895,295.95957&#xd;&#xa;461.96393,305.03607 448,319 480.77307,319 511.67465,307.44178 543,297 516.94816,297 489.53212,303 465,303 493.73654,308.74731 525.95507,292 556,292 554,292.66667 552.03262,293.44062 550,294 528.94498,299.79439 507.18576,302.70356 486,308 479.14768,309.71308 472.61349,312.51994 466,315 464.6042,315.52342 462.78371,315.73192 462,317&#xd;&#xa;461.64951,317.5671 462,318.33333 462,319 478.75613,319 504.35885,325.82057 520,318 511.13669,318 509.5023,316.4977 502,324 510.30613,332.30613 534.5281,326 548,326 566.45477,326 586.86183,329.53454 605,325 572.9348,325 549.14831,337.95056 519,348 535.26344,364.26344 581.48389,343 606,343 593.28018,343 581.97566,343.01217&#xd;&#xa;570,349 577.66667,349 585.33333,349 593,349 581.81331,349 571.10914,358 616,358 612.59069,359.02279 553.11658,371.37219 585,382 596.73005,385.91002 605.58993,387 618,387 607.83527,387 602.2498,385.10008 595,388 612.1254,393.70847 626.57294,395 645,395 636.34669,399.32665 626.77848,401.61076 618,406 627.69547,415.69547&#xd;&#xa;645.04856,412 660,412 659.66667,412.33333 659.33333,412.66667 659,413 675.23864,421.11932 671.16257,421 694,421 688.68774,421 684.20309,420.26564 679,422 681.33333,422 683.66667,422 686,422 684,422.66667 681.94771,423.19323 680,424 678.62276,424.57047 677.33333,425.33333 676,426 677,426 678,426 679,426&#xd;&#xa;678.36086,426.38348 677.60466,426.56418 677,427 676.61758,427.27564 676.29448,427.63189 676,428 691.08197,428 704.0128,436 720,436 719.66667,436.33333 719.33333,436.66667 719,437" />

       </Window.Resources>

      

       <Canvas>

 

             <Path Stroke="Black" StrokeThickness="3" Data="{StaticResource path1}" />

 

             <Button Content="슈웅~" Width="80" Height="30" RenderTransformOrigin="0.5,0.5">

                    <Button.RenderTransform>

                           <TransformGroup>

                                 <TranslateTransform x:Name="tTrans" />

                                 <RotateTransform x:Name="rTrans" />

                                 <TranslateTransform X="-40" Y="-15" />

                           </TransformGroup>

                    </Button.RenderTransform>

                    <Button.Triggers>

                           <EventTrigger RoutedEvent="Button.Click">

                                 <BeginStoryboard>

                                        <Storyboard>

                                              <DoubleAnimationUsingPath

                           Storyboard.TargetProperty="(Canvas.Left)"

                           Duration="0:0:10" AutoReverse="True"

                           RepeatBehavior="10x"

                           PathGeometry="{StaticResource path1}"

                           Source="X"

                                                     />

                                              <DoubleAnimationUsingPath

                           Storyboard.TargetProperty="(Canvas.Top)"

                           Duration="0:0:10" AutoReverse="True"

                           RepeatBehavior="10x"

                           PathGeometry="{StaticResource path1}"

                           Source="Y"

                                                     />

                                              <DoubleAnimationUsingPath

                           Storyboard.TargetName="rTrans"

                           Storyboard.TargetProperty="Angle"

                           Duration="0:0:10" AutoReverse="True"

                           RepeatBehavior="10x"

                           PathGeometry="{StaticResource path1}"

                           Source="Angle"

                                                     />

                                        </Storyboard>

                                 </BeginStoryboard>

                           </EventTrigger>

                    </Button.Triggers>

             </Button>

 

       </Canvas>

 

</Window>

 

 

저작자표시

트랙백

※ 스팸 트랙백 차단중 ...{ ? }

WPF 스타일 내부 트리거, 변형객체 애니메이션



<!--

       1. 스타일 사용해서 모든 버튼의 속성 설정

       2. 스타일 내부에 변형 객체 추가(변형 역시 속성 중 하나)

       3. 스타일 내부에 트리거 추가(속성, 이벤트)

          3.1 이벤트 트리거 추가

          3.2 클릭 => 변형 객체를 애니메이션 실행

       스타일은 1개이상의 객체를 전제로 하기 때문에 x:Name은 불가능 하다.

-->

      

<Window x:Class="WPFEx.Animation16"

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

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

        Title="Animation16" Height="300" Width="300">

      

       <Window.Resources>

            

             <Style TargetType="{x:Type Button}">

                    <Setter Property="Content" Value="Click" />

                    <Setter Property="RenderTransformOrigin" Value="0.5,0.5" />

                    <Setter Property="RenderTransform">

                           <Setter.Value>

                                 <ScaleTransform />

                           </Setter.Value>

                    </Setter>

                   

                    <Style.Triggers>

                           <EventTrigger RoutedEvent="Button.Click">

                                 <BeginStoryboard>

                                        <Storyboard>

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

<DoubleAnimation From="1" To="0.5" Duration="0:0:0.5" AutoReverse="True" RepeatBehavior="Forever" Storyboard.TargetProperty="RenderTransform.ScaleY" />

                                        </Storyboard>

                                 </BeginStoryboard>

                           </EventTrigger>

                    </Style.Triggers>

                   

             </Style>

       </Window.Resources>

      

       <UniformGrid>

             <Button />

             <Button />

             <Button />

             <Button />

             <Button />

             <Button />

             <Button />

             <Button />

             <Button />

       </UniformGrid>

      

</Window>

 
 

Style  컨트롤 Xaml

<Window x:Class="WPFEx.Animation17"

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

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

        Title="Animation17" Height="500" Width="300" Loaded="Window_Loaded" >

       <Window.Resources>

             <Style TargetType="{x:Type Button}">

                    <Setter Property="Width" Value="50" />

                    <Setter Property="Height" Value="50" />

                    <Setter Property="VerticalAlignment" Value="Bottom" />

                    <Setter Property="RenderTransformOrigin" Value="0.5,0.5" />

                    <Setter Property="RenderTransform">

                           <Setter.Value>

                                 <TranslateTransform />

                           </Setter.Value>

                    </Setter>

                    <Style.Triggers>

                           <EventTrigger RoutedEvent="MouseEnter">

                                 <BeginStoryboard>

                                        <Storyboard>

                                              <DoubleAnimation Storyboard.TargetProperty="RenderTransform.Y" By="-50" Duration="0:0:0.3" />

                                        </Storyboard>

                                 </BeginStoryboard>

                           </EventTrigger>

                    </Style.Triggers>

             </Style>

                      

       </Window.Resources>

 

             <Grid Name="grid1">

       

    </Grid>

</Window>

 

 

Style  컨트롤 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;

 

namespace WPFEx

{

       /// <summary>

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

       /// </summary>

       public partial class Animation17 : Window

       {

             public Animation17()

             {

                    InitializeComponent();

             }

 

             private void Window_Loaded(object sender, RoutedEventArgs e)

             {

                    for (int i = 0; i < 100; i++)

                    {

                           Button btn = new Button();

                           //btn.Content = i.ToString();

                           //btn.Click += new RoutedEventHandler(btn_Click);

                           grid1.Children.Add(btn);

                    }

             }

 

             void btn_Click(object sender, RoutedEventArgs e)

             {

                    // as 형변환 연산자 Button btn = (Button)e.Source; 와 같은 형태

                    // 기존에 캐스팅 연산자는 실패를 하게 되면 런타임에러가 발생 as를 사용하게 되면 null을 반환한다.

                    // WPF는 sender 누가 호출 했는지 ? 판단을 Source로 판단한다.

                    Button btn = e.Source as Button;

 

                    grid1.Children.Remove(btn);

             }

       }

}

 

  


<Window x:Class="WPFEx.Animation18"

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

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

        Title="Animation18" Height="500" Width="800">

      

<TextBlock Text="XAML" FontSize="300" FontFamily="Impact" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin=".5,.5">

      

       <TextBlock.RenderTransform>

             <TransformGroup>

                    <TransformGroup.Children>

                                 <!--

                                 변형 객체를 2개이상 동시에 적용

                                 RenderTransform은 Content가짐!!!

                                 => 변형 객체를 1개만 가질 수 있다 1개이상 가지고 싶으면 TextBox 자식으로 TransformGroup을 가지고 그룹을 선언하면 Children을 제외하고 사용한다 대부분

                                 -->

                                 <RotateTransform x:Name="rTrans" />

                                 <ScaleTransform x:Name="sTrans" />

                           </TransformGroup.Children>

                    </TransformGroup>

       </TextBlock.RenderTransform>

      

       <TextBlock.Triggers>

             <EventTrigger RoutedEvent="TextBlock.MouseDown">

                    <BeginStoryboard>

                           <Storyboard>

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

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

                           </Storyboard>

                    </BeginStoryboard>

             </EventTrigger>

       </TextBlock.Triggers>

      

       </TextBlock>

      

      

      

</Window>

 

 <Window x:Class="WPFEx.Animation19"

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

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

        Title="Animation19" Height="300" Width="500">

      

       <Window.Resources>

            

             <Style TargetType="{x:Type Button}">

                    <Setter Property="Width" Value="80" />

                    <Setter Property="Height" Value="80" />

                    <Setter Property="Margin" Value="2" />

                    <Setter Property="FocusVisualStyle" Value="{x:Null}" />

                    <Setter Property="RenderTransformOrigin" Value="0.5,0.5" />

                    <Setter Property="RenderTransform">

                           <Setter.Value>

                                 <RotateTransform Angle="0" />

                           </Setter.Value>

                    </Setter>

                    <Style.Triggers>

                           <EventTrigger RoutedEvent="Button.MouseEnter">

                                 <BeginStoryboard>

                                        <Storyboard>

<DoubleAnimation Storyboard.TargetProperty="Width" To="120" Duration="0:0:0.3" AutoReverse="False" />

<DoubleAnimation Storyboard.TargetProperty="Height" To="120" Duration="0:0:0.3" AutoReverse="False" />

                                        </Storyboard>

                                 </BeginStoryboard>

                           </EventTrigger>

                                               

                           <EventTrigger RoutedEvent="Button.MouseLeave">

                           <BeginStoryboard>

                                 <Storyboard>

                                        <DoubleAnimation Storyboard.TargetProperty="Width" To="80" Duration="0:0:0.3" AutoReverse="False" />

                                        <DoubleAnimation Storyboard.TargetProperty="Height" To="80" Duration="0:0:0.3" AutoReverse="False" />

                                 </Storyboard>

                           </BeginStoryboard>

                           </EventTrigger>

 

                           <EventTrigger RoutedEvent="Button.Click">

                                 <BeginStoryboard>

                                        <Storyboard>

                                              <DoubleAnimation Storyboard.TargetProperty="RenderTransform.Angle" From="0" To="360" Duration="0:0:0.3" RepeatBehavior="5x" />

                                        </Storyboard>

                                 </BeginStoryboard>

                           </EventTrigger>

 

                    </Style.Triggers>

             </Style>

                     

       </Window.Resources>

      

       <!--메뉴바-->

       <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">

            

             <Button Content="메뉴1" />

             <Button Content="메뉴2" />

             <Button Content="메뉴3" />

             <Button Content="메뉴4" />

             <Button Content="메뉴5" />

            

       </StackPanel>

      

</Window>

 

 

 
이것을 C#으로 제어 하고싶다면
story2.Begin();
story2.Pause();
story2.Resume();
story2.Stop();
story2.Seek(TimeSpan.FromSeconds(2.5));
 <!--

       스토리보드(행동집합, 시간흐름)

             : 애니메이션의 집합

             : 행동 + 시간

             => 제어(시작,중지) => 곰플레이어(시작, 일시중지, 다시시작, 멈춤)

-->

      

<Window x:Class="WPFEx.MiniProject02"

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

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

        Title="MiniProject02" Height="500" Width="700">

      

       <StackPanel>

            

             <Canvas Width="350" Height="200" Background="Firebrick">

                    <Rectangle Stroke="Black" StrokeThickness="5" Fill="Tan" Width="50" Height="150" Canvas.Left="150" Canvas.Top="50">

                           <Rectangle.RenderTransform>

                                 <TransformGroup>

                                        <RotateTransform x:Name="rTrans1" Angle="-90" CenterX="0" CenterY="150" />

                                        <RotateTransform x:Name="rTrans2" Angle="0" CenterX="50" CenterY="150" />

                                 </TransformGroup>

                           </Rectangle.RenderTransform>

                    </Rectangle>

             </Canvas>

            

             <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Background="RosyBrown">

 

                    <StackPanel.Triggers>

                         &nbs