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

TestProject.zip
0.01MB

▶ MainWindow.xaml

<Window x:Class="TestProject.MainWindow" Name="window"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="800"
    Height="600"
    Title="DoubleAnimation 클래스 : 화면을 반짝이는 애니메이션 사용하기"
    Background="#ff000000"
    Foreground="#ff3ee229">
    <Grid>
        <TextBlock
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            FontSize="96">
            ANIMATION
        </TextBlock>
        <Canvas Panel.ZIndex="99">
            <Rectangle Name="rectangle"
                Width="{Binding Path=ActualWidth, ElementName=window, Mode=Default}"
                Height="{Binding Path=ActualHeight, ElementName=window, Mode=Default}"
                Opacity="0.4">
                <Rectangle.Triggers>
                    <EventTrigger RoutedEvent="Rectangle.Loaded">
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation
                                    Storyboard.TargetName="rectangle" 
                                    Storyboard.TargetProperty="(Canvas.Left)"
                                    From="-500"
                                    To="1000"
                                    Duration="0:0:2" />
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </Rectangle.Triggers>
                <Rectangle.Fill>
                    <LinearGradientBrush
                        StartPoint="0 1"
                        EndPoint="1 1">
                        <GradientStop Color="Transparent" Offset="0.0"  />
                        <GradientStop Color="LightGreen"  Offset="0.50" />
                        <GradientStop Color="Transparent" Offset="1"    />
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        </Canvas>
    </Grid>
</Window>

 

728x90

 

▶ MainWindow.xaml.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Animation;

namespace TestProject
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public partial class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            MouseDown += Window_MouseDown;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 윈도우 마우스 DOWN 처리하기 - Window_MouseDown(sender, e)

        /// <summary>
        /// 윈도우 마우스 DOWN 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Window_MouseDown(object sender, MouseButtonEventArgs e)
        {
            this.rectangle.Width  = Width;
            this.rectangle.Height = Height;

            DoubleAnimation animation = new DoubleAnimation
            {
                Duration = new Duration(TimeSpan.FromSeconds(2)),
                From     = (-Width),
                To       = Width * 2
            };

            this.rectangle.BeginAnimation(Canvas.LeftProperty, animation);
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요