[C#/WPF] Storyboard 클래스 : Begin/Pause/Resume/SkipToFill/SetSpeedRatio/Stop 메소드 사용하기
C#/WPF 2020. 9. 11. 22:33728x90
반응형
728x170
▶ MainWindow.xaml
<Window x:Class="TestProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="800"
Height="600"
Title="Storyboard 클래스 : Begin/Pause/Resume/SkipToFill/SetSpeedRatio/Stop 메소드 사용하기"
FontFamily="나눔고딕코딩"
FontSize="16">
<Grid>
<StackPanel
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Rectangle Name="rectangle"
Width="100"
Height="100"
Fill="Blue" />
<StackPanel
Margin="10"
Orientation="Horizontal">
<Button Name="beginButton"
Margin="5"
Padding="10"
Content="Begin" />
<Button Name="pauseButton"
Margin="5"
Padding="10"
Content="Pause" />
<Button Name="resumeButton"
Margin="5"
Padding="10"
Content="Resume" />
<Button Name="skipToFillButton"
Margin="5"
Padding="10"
Content="Skip to Fill" />
<Button Name="tripleSpeedButton"
Margin="5"
Padding="10"
Content="Triple Speed" />
<Button Name="stopButton"
Margin="5"
Padding="10"
Content="Stop" />
</StackPanel>
</StackPanel>
</Grid>
</Window>
728x90
▶ MainWindow.xaml.cs
using System;
using System.Windows;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace TestProject
{
/// <summary>
/// 메인 윈도우
/// </summary>
public partial class MainWindow : Window
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 스토리 보드
/// </summary>
private Storyboard storyboard;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainWindow()
/// <summary>
/// 생성자
/// </summary>
public MainWindow()
{
InitializeComponent();
this.storyboard = new Storyboard();
DoubleAnimation doubleAnimation = new DoubleAnimation();
doubleAnimation.From = 1.0;
doubleAnimation.To = 0.0;
doubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(5000));
Storyboard.SetTargetName (doubleAnimation, this.rectangle.Name);
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(Rectangle.OpacityProperty));
this.storyboard.Children.Add(doubleAnimation);
this.beginButton.Click += beginButton_Click;
this.pauseButton.Click += pauseButton_Click;
this.resumeButton.Click += resumeButton_Click;
this.skipToFillButton.Click += skipToFillButton_Click;
this.tripleSpeedButton.Click += tripleSpeedButton_Click;
this.stopButton.Click += stopButton_Click;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Begin 버튼 클릭시 처리하기 - beginButton_Click(sender, e)
/// <summary>
/// Begin 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void beginButton_Click(object sender, RoutedEventArgs e)
{
this.storyboard.Begin(this, true);
}
#endregion
#region Pause 버튼 클릭시 처리하기 - pauseButton_Click(sender, e)
/// <summary>
/// Pause 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void pauseButton_Click(object sender, RoutedEventArgs e)
{
this.storyboard.Pause(this);
}
#endregion
#region Resume 버튼 클릭시 처리하기 - resumeButton_Click(sender, e)
/// <summary>
/// Resume 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void resumeButton_Click(object sender, RoutedEventArgs e)
{
this.storyboard.Resume(this);
}
#endregion
#region Skip to Fill 버튼 클릭시 처리하기 - skipToFillButton_Click(sender, e)
/// <summary>
/// Skip to Fill 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void skipToFillButton_Click(object sender, RoutedEventArgs e)
{
this.storyboard.SkipToFill(this);
}
#endregion
#region Triple Speed 버튼 클릭시 처리하기 - tripleSpeedButton_Click(sender, e)
/// <summary>
/// Triple Speed 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void tripleSpeedButton_Click(object sender, RoutedEventArgs e)
{
this.storyboard.SetSpeedRatio(this, 3);
}
#endregion
#region Stop 버튼 클릭시 처리하기 - stopButton_Click(sender, e)
/// <summary>
/// Stop 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void stopButton_Click(object sender, RoutedEventArgs e)
{
this.storyboard.Stop(this);
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] Grid 클래스 : 자동 인덱스 설정 그리드 사용하기 (0) | 2020.09.13 |
---|---|
[C#/WPF] Material 메뉴 사용하기 (0) | 2020.09.13 |
[C#/WPF] Animatable 클래스 : BeginAnimation 메소드를 사용해 공 움직이기 (0) | 2020.09.11 |
[C#/WPF] UIElement 클래스 : BeginAnimation 메소드를 사용해 애니메이션 시작하기 (0) | 2020.09.11 |
[C#/WPF] DoubleAnimation 클래스 : 사각형 높이 변경하기 (0) | 2020.09.11 |
[C#/WPF] TreeView 엘리먼트 : AlternationConverter 객체를 사용해 트리 뷰 항목 배경색/폰트 스타일 설정하기 (0) | 2020.09.11 |
[C#/WPF] VisualBrush 엘리먼트 : 엘리먼트 반사 그림자 이미지 만들기 (0) | 2020.09.11 |
[C#/WPF] DrawingBrush 엘리먼트 : Drawing 속성을 사용해 물고기 브러시 만들기 (0) | 2020.09.11 |
[C#/WPF] DrawingContext 클래스 : DrawDrawing 메소드를 사용해 드로잉 그리기 (0) | 2020.09.11 |
[C#/WPF] DrawingContext 클래스 : DrawImage 메소드를 사용해 이미지 그리기 (0) | 2020.09.11 |
댓글을 달아 주세요