728x90
반응형
728x170
■ 이미지를 뒤집는 방법을 보여준다.
▶ UIHelper.cs
using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace TestProject
{
/// <summary>
/// UI 헬퍼
/// </summary>
public class UIHelper
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Public
#region 플립하기 - Flip(window, source, target)
/// <summary>
/// 플립하기
/// </summary>
/// <param name="window">윈도우</param>
/// <param name="source">소스</param>
/// <param name="target">타겟</param>
public static void Flip(Window window, UIElement source, UIElement target)
{
if(source == null)
{
throw new ArgumentOutOfRangeException("source");
}
if(target == null)
{
throw new ArgumentOutOfRangeException("target");
}
Storyboard storyboard = new Storyboard();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("(UIElement.RenderTransform).(ScaleTransform.ScaleY)"));
source.RenderTransformOrigin = new Point(0.5, 0.5);
target.RenderTransformOrigin = new Point(0.5, 0.5);
source.RenderTransform = new ScaleTransform(1, 1);
target.RenderTransform = new ScaleTransform(1, 0);
DoubleAnimation outDoubleAnimation = new DoubleAnimation(1, 0, TimeSpan.FromMilliseconds(200));
DoubleAnimation inDoubleAnimation = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(200));
inDoubleAnimation.BeginTime = TimeSpan.FromMilliseconds(200);
Storyboard.SetTargetName(outDoubleAnimation, (source as FrameworkElement).Name);
Storyboard.SetTargetName(inDoubleAnimation , (target as FrameworkElement).Name);
storyboard.Children.Add(outDoubleAnimation);
storyboard.Children.Add(inDoubleAnimation);
storyboard.Begin(window);
}
#endregion
}
}
▶ 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="이미지 뒤집기"
FontFamily="나눔고딕코딩"
FontSize="16">
<StackPanel
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Grid>
<Image x:Name="firstImage"
Width="400"
Height="300"
Source="Image/koala.jpg" />
<Image x:Name="secondImage"
Width="400"
Height="300"
Source="Image/penguins.jpg" />
</Grid>
<Button x:Name="button"
Margin="0,10,0,0"
VerticalAlignment="Bottom"
Height="30"
Content="Change" />
</StackPanel>
</Window>
▶ MainWindow.xaml.cs
using System.Windows;
namespace TestProject
{
/// <summary>
/// 메인 윈도우
/// </summary>
public partial class MainWindow : Window
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 첫번째 이미지 표시 여부
/// </summary>
private bool showFirstImage = true;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainWindow()
/// <summary>
/// 생성자
/// </summary>
public MainWindow()
{
InitializeComponent();
this.button.Click += button_Click;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 버튼 클릭시 처리하기 - button_Click(sender, e)
/// <summary>
/// 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void button_Click(object sender, RoutedEventArgs e)
{
if(!this.showFirstImage)
{
UIHelper.Flip(this, this.firstImage, this.secondImage);
}
else
{
UIHelper.Flip(this, this.secondImage, this.firstImage);
}
this.showFirstImage = !this.showFirstImage;
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] XAML에서 특수 문자 사용하기 (0) | 2018.03.04 |
---|---|
[C#/WPF] MediaElement 클래스 사용하기 (0) | 2018.02.18 |
[C#/WPF] RotateTransform 엘리먼트 : 마우스 진입시 이미지 회전하기 (0) | 2018.02.18 |
[C#/WPF] DoubleAnimation 엘리먼트 : 스크롤 슬라이드 사용하기 (0) | 2018.02.18 |
[C#/WPF] 이미지 뒤집기 (0) | 2018.02.18 |
[C#/WPF] 이미지 슬라이드 쇼 보여주기 (0) | 2018.02.18 |
[C#/WPF] 애니메이션 사용하기 (0) | 2018.02.18 |
[C#/WPF] XAML 시계 사용하기 (0) | 2018.02.18 |
[C#/WPF] FormattedText 클래스 : BuildGeometry 메소드를 사용해 텍스트 효과 만들기 (0) | 2018.02.18 |
[C#/WPF] 스플라인 키 프레임 애니메이션 사용하기 (0) | 2018.02.18 |
댓글을 달아 주세요