첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ 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
    }
}

 

728x90

 

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

 

300x250

 

▶ 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
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요