Timer Design in StatusBar

Timer in StatusBar

  1. we need to show local time in StatusBar. solution: 1. add textblock control 2. binding to a string. 3. we use dispatcherTimer class to update the string.
  2. DispatcherTimer class
  3. Code Example:

XAML:

    <StatusBarItem HorizontalAlignment="Left" Margin="10,0,0,0">
<TextBlock Text="当前时间: " />
</StatusBarItem>
<StatusBarItem HorizontalAlignment="Left">
<TextBlock Text="{Binding CurrentTime}" />
</StatusBarItem>

c#:

        public string CurrentTime
{
get
{
return _currentTime;
}
set
{
_currentTime = value;
RaisePropertyChanged("");
}
}
private void UpdateTime( object sender, EventArgs e)
{
CurrentTime = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
}
timer = new DispatcherTimer();
timer.Interval = new TimeSpan(0,0,1);
timer.Tick += new EventHandler(UpdateTime);
timer.Start();
上一篇:InterProScan 5.17-56.0 安装和使用


下一篇:练习 map集合被使用是因为具备映射关系 "进度班" "01" "张三" "进度班" "02" "李四" "J1701" "01" "王五" "J1701" "02" "王二" 此信息中,我们要怎样把上述信息装入集合中, 根据班级信息的到所有的所有信