2009/05/12 01:58

Silverlight – DispatcherTimer , Clock

 

DispatcherTimer 를 이용해 시계를 만들어보도록 한다.

먼저 using으로 using System.Windows.Threading; Namespace를 추가해야 하고 다음을 따라 진행한다

  1. Xaml

     

<UserControl x:Class="ClockSample.Page"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Width="400" Height="300">

<Grid x:Name="LayoutRoot" Background="White">

<TextBlock FontSize="60" TextAlignment="Center" VerticalAlignment="Center" x:Name="tbTime" Text="12:00:00" />

</Grid>

</UserControl>

 

 

  1. Code

 

public Page()

{

InitializeComponent();

 

 

TimerSetting();

}

 

private void TimerSetting()

{

DispatcherTimer timer = new DispatcherTimer()

{

Interval = TimeSpan.FromMilliseconds(50)

};

 

timer.Tick += new EventHandler(timer_Tick);

 

timer.Start();

}

 

void timer_Tick(object sender, EventArgs e)

{

this.tbTime.Text = DateTime.Now.ToString("HH:mm:ss");

}

 

  1. 다음과 같이 시계가 잘 작동한다.

     

저작자 표시 비영리 변경 금지
이올린에 북마크하기(0) 이올린에 추천하기(0)
크리에이티브 커먼즈 라이선스
Creative Commons License

'.NET > Silverlight' 카테고리의 다른 글

Silverlight Custom control  (0) 2009/06/23
Silverlight – bubbling events  (2) 2009/05/18
Silverlight – DispatcherTimer , Clock  (0) 2009/05/12
Silverlight – Dynamic Page load  (0) 2009/05/10
Silverlight – Host Settings  (0) 2009/05/10
Silverlight OpenFileDialog  (0) 2009/05/07
올블로그추천버튼 블코추천버튼 블로그뉴스추천버튼 믹시추천버튼 한RSS추가버튼 구글리더기추천버튼


이 포스팅이 도움이 되었다면 구글에서 관련 정보를 찾아 보세요 ^^


Trackback 0 Comment 0

Trackback : http://i-ruru.com/trackback/456 관련글 쓰기