Dev/Silveright

실버라이트 - DispatcherTimer 이용한 타이머 만들기

쇼크리더 2008. 8. 7. 17:08
반응형

1.1 책 보면서 2.0 공부할라니까 많이 헷갈린다.

xmal 소스
 <Grid x:Name="LayoutRoot" Background="White" >
  <TextBox HorizontalAlignment="Left" VerticalAlignment="Top" Text="TextBox" TextWrapping="Wrap" Margin="33,78,0,0" Width="277.896" x:Name="txtBox"/>
 </Grid>


cs 소스
//추가로 필요한 네임스페이스
using System.Windows.Threading;

  public Page()
  {
   InitializeComponent();
   
   DispatcherTimer timer = new DispatcherTimer();
   timer.Interval = TimeSpan.FromMilliseconds(1000); // 1초
   // timer.Interval = new TimeSpan(0, 0, 0, 0, 1000); // 1초

   timer.Tick += new EventHandler(timer_Tick);

   txtBox.Text = DateTime.Now.ToString();

   timer.Start();
  }

  private void timer_Tick(object sender, EventArgs e)
  {
   txtBox.Text = DateTime.Now.ToString();
  }

반응형