첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.

728x90
반응형
728x170

TestProject.zip
0.01MB

▶ 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 엘리먼트 : 컨트롤 템플리트 내에서 사용하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid>
        <Button Name="button"
            Width="100"
            Height="100">
            <Button.Template>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid Name="rootGrid"
                        Background="Transparent"
                        MouseEnter="rootGrid_MouseEnter"
                        MouseLeave="rootGrid_MouseEnter">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="Layout">
                                <VisualState x:Name="EllipseState">
                                    <Storyboard>
                                        <DoubleAnimation
                                            Storyboard.TargetName="ellipse"
                                            Storyboard.TargetProperty="(UIElement.Opacity)"
                                            Duration="00:00:01"
                                            To="1" />
                                        <DoubleAnimation
                                            Storyboard.TargetName="rectangle"
                                            Storyboard.TargetProperty="(UIElement.Opacity)"
                                            Duration="00:00:01"
                                            To="0" />
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="RectangleState">
                                    <Storyboard>
                                        <DoubleAnimation
                                            Storyboard.TargetName="ellipse"
                                            Storyboard.TargetProperty="(UIElement.Opacity)"
                                            Duration="00:00:01"
                                            To="0" />
                                        <DoubleAnimation
                                            Storyboard.TargetName="rectangle"
                                            Storyboard.TargetProperty="(UIElement.Opacity)"
                                            Duration="00:00:01"
                                            To="1" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Rectangle Name="rectangle"
                            Stroke="Black"
                            Fill="Blue"
                            Opacity="0" />
                        <Ellipse Name="ellipse"
                            Stroke="Black"
                            Fill="Orange"
                            Opacity="1" />
                    </Grid>
                </ControlTemplate>            
            </Button.Template>
        </Button>
    </Grid>
</Window>

 

728x90

 

▶ MainWindow.xaml.cs

using System.Windows;
using System.Windows.Input;

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

        #region 생성자 - MainWindow()

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

        #endregion

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

        #region 루트 그리드 마우스 진입시 처리하기 - rootGrid_MouseEnter(sender, e)

        /// <summary>
        /// 루트 그리드 마우스 진입시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void rootGrid_MouseEnter(object sender, MouseEventArgs e)
        {
            if(this.button.IsMouseOver)
            {
                VisualStateManager.GoToState(this.button, "RectangleState", true);
            }
            else
            {
                VisualStateManager.GoToState(this.button, "EllipseState", true);
            }
        }

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

댓글을 달아 주세요