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

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="XAML 시계 사용하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Window.Resources>
        <Style TargetType="{x:Type Path}">
            <Setter Property="Stroke"             Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
            <Setter Property="StrokeThickness"    Value="2"     />
            <Setter Property="StrokeStartLineCap" Value="Round" />
            <Setter Property="StrokeEndLineCap"   Value="Round" />
            <Setter Property="StrokeLineJoin"     Value="Round" />
            <Setter Property="StrokeDashCap"      Value="Round" />
        </Style>
    </Window.Resources>
    <Viewbox>
        <Canvas
            Width="200"
            Height="200">
            <Canvas.RenderTransform>
                <TranslateTransform X="100" Y="100" />
            </Canvas.RenderTransform>
            <Path
                Stroke="Blue"
                StrokeDashArray="0 3.14159"
                StrokeThickness="3"
                Data="M 0 -90 A 90 90 0 1 1 -0.01 -90" />
            <Path
                Stroke="DarkBlue"
                StrokeDashArray="0 7.854"
                StrokeThickness="6"
                Data="M 0 -90 A 90 90 0 1 1 -0.01 -90" />
            <!-- 시침 -->
            <Path
                Fill="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"
                Data="M 0 15 L 10 0, 0 -60, -10 0 Z">
                <Path.RenderTransform>
                    <RotateTransform x:Name="hourRotateTransform" />
                </Path.RenderTransform>
            </Path>
            <!-- 분침 -->
            <Path
                Fill="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}"
                Data="M 0 20 L 5 0 0 -80 -5 0 Z">
                <Path.RenderTransform>
                    <RotateTransform x:Name="minuteRotateTransform" />
                </Path.RenderTransform>
            </Path>
            <!-- 초침 -->
            <Path Data="M 0 10 L 0 -80">
                <Path.RenderTransform>
                    <RotateTransform x:Name="secondRotateTransform" />
                </Path.RenderTransform>
            </Path>
        </Canvas>
    </Viewbox>
    <Window.Triggers>
        <EventTrigger
            RoutedEvent="Canvas.Loaded">
            <BeginStoryboard>
                <Storyboard Name="storyboard">
                    <DoubleAnimation
                        Storyboard.TargetName="hourRotateTransform"
                        Storyboard.TargetProperty="Angle"
                        RepeatBehavior="Forever"
                        Duration="12:0:0"
                        From="0"
                        To="360" />
                    <DoubleAnimation
                        Storyboard.TargetName="minuteRotateTransform"
                        Storyboard.TargetProperty="Angle"
                        RepeatBehavior="Forever"
                        Duration="1:0:0"
                        From="0"
                        To="360" />
                    <DoubleAnimation
                        Storyboard.TargetName="secondRotateTransform"
                        Storyboard.TargetProperty="Angle"
                        RepeatBehavior="Forever"
                        Duration="0:1:0"
                        From="0"
                        To="360" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Window.Triggers>
</Window>

 

728x90

 

▶ MainWindow.xaml.cs

using System;
using System.Windows;

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

        #region 생성자 - MainWindow()

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

            this.storyboard.BeginTime = -DateTime.Now.TimeOfDay;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

        #region 프로그램 시작하기 - Main()

        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        [STAThread]
        private static void Main()
        {
            Application application = new Application();

            application.Run(new MainWindow());
        }

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

댓글을 달아 주세요