728x90
반응형
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="DoubleAnimation 클래스 : 사각형 높이 변경하기"
FontFamily="나눔고딕코딩"
FontSize="16">
<Grid>
<Rectangle Name="rectangle"
Width="200"
Height="200">
<Rectangle.Fill>
<LinearGradientBrush
StartPoint="0 0"
EndPoint="0 1">
<GradientStop Offset="0" Color="Red" />
<GradientStop Offset="0.5" Color="Purple" />
<GradientStop Offset="1" Color="Blue" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</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
(
200d,
100d,
new Duration(TimeSpan.FromSeconds(2))
);
doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
doubleAnimation.AutoReverse = true;
doubleAnimation.BeginTime = TimeSpan.FromSeconds(0.5);
Storyboard.SetTargetName (doubleAnimation, this.rectangle.Name);
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(Rectangle.HeightProperty));
this.storyboard.Children.Add(doubleAnimation);
Loaded += Window_Loaded;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 윈도우 로드시 처리하기 - Window_Loaded(sender, e)
/// <summary>
/// 윈도우 로드시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.storyboard.Begin(this);
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] BindingOperations 클래스 : ClearBinding/SetBinding 정적 메소드를 사용해 바인딩하기 (0) | 2020.09.14 |
---|---|
[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] Storyboard 클래스 : Begin/Pause/Resume/SkipToFill/SetSpeedRatio/Stop 메소드 사용하기 (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 |
댓글을 달아 주세요