첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

■ VisualStateManager 클래스 사용하기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


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="VisualStateManager 클래스 사용하기">

    <Grid>

        <Rectangle Name="rectangle" Width="100" Height="100">

            <VisualStateManager.VisualStateGroups>

                <VisualStateGroup Name="MouseStates">

                    <VisualState Name="MouseEnter">

                        <Storyboard>

                            <ColorAnimation Storyboard.TargetName="rectangleBrush" Storyboard.TargetProperty="Color" To="Green" />

                        </Storyboard>

                    </VisualState>

                    <VisualState Name="MouseLeave" />

                    <VisualStateGroup.Transitions>

                        <VisualTransition To="MouseLeave" GeneratedDuration="00:00:00" />

                        <VisualTransition To="MouseEnter" GeneratedDuration="00:00:00">

                            <VisualTransition.GeneratedEasingFunction>

                                <ExponentialEase EasingMode="EaseOut" Exponent="10" />

                            </VisualTransition.GeneratedEasingFunction>

                        </VisualTransition>

                    </VisualStateGroup.Transitions>

                </VisualStateGroup>

            </VisualStateManager.VisualStateGroups>

            <Rectangle.Fill>

                <SolidColorBrush x:Name="rectangleBrush" Color="Red" />

            </Rectangle.Fill>

        </Rectangle>

    </Grid>

</Window>

 

 

MainWindow.xaml.cs

 

 

using System.Windows;

using System.Windows.Input;

using System.Windows.Shapes;

 

namespace TestProject

{

    /// <summary>

    /// 메인 윈도우

    /// </summary>

    public partial class MainWindow : Window

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainWindow()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainWindow()

        {

            InitializeComponent();

 

            this.rectangle.MouseEnter += rectangle_MouseEnter;

            this.rectangle.MouseLeave += rectangle_MouseLeave;

 

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region 사각형 마우스 진입시 처리하기 - rectangle_MouseEnter(sender, e)

 

        /// <summary>

        /// 사각형 마우스 진입시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void rectangle_MouseEnter(object sender, MouseEventArgs e)

        {

            VisualStateManager.GoToElementState(sender as Rectangle, "MouseEnter", true);

        }

 

        #endregion

        #region 사각형 마우스 이탈시 처리하기 - rectangle_MouseLeave(sender, e)

 

        /// <summary>

        /// 사각형 마우스 이탈시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void rectangle_MouseLeave(object sender, MouseEventArgs e)

        {

            VisualStateManager.GoToElementState(sender as Rectangle, "MouseLeave", true);

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요