728x90
반응형
728x170
■ XAML로 시계를 만드는 방법을 보여준다.
▶ 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>
▶ 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
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] DoubleAnimation 엘리먼트 : 스크롤 슬라이드 사용하기 (0) | 2018.02.18 |
---|---|
[C#/WPF] 이미지 뒤집기 (0) | 2018.02.18 |
[C#/WPF] 이미지 뒤집기 (0) | 2018.02.18 |
[C#/WPF] 이미지 슬라이드 쇼 보여주기 (0) | 2018.02.18 |
[C#/WPF] 애니메이션 사용하기 (0) | 2018.02.18 |
[C#/WPF] FormattedText 클래스 : BuildGeometry 메소드를 사용해 텍스트 효과 만들기 (0) | 2018.02.18 |
[C#/WPF] 스플라인 키 프레임 애니메이션 사용하기 (0) | 2018.02.18 |
[C#/WPF] Shape 클래스 : 펜 사용하기 (0) | 2018.02.18 |
[C#/WPF] 파티클 애니메이션 사용하기 (0) | 2018.02.18 |
[C#/WPF] 마우스 애니메이션 사용하기 (0) | 2018.02.18 |
댓글을 달아 주세요