<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="SLTimer.MainPage"
Width="640" Height="480">
<Grid x:Name="LayoutRoot" Background="White" Loaded="LayoutRoot_Loaded">
<TextBlock Height="21" HorizontalAlignment="Left" Margin="127,75,0" VerticalAlignment="Top" Width="57" Text="当前时间:" textwrapping="Wrap" FontSize="12" Foreground="#FF315DAB"/>
<TextBlock x:Name="tbTime" Height="21" Margin="188,94,0" VerticalAlignment="Top" textwrapping="Wrap"/>
</Grid>
</UserControl>
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace SLTimer
{
public partial class MainPage : UserControl
{
public MainPage()
{
// 为初始化变量所必需
InitializeComponent();
}
private void LayoutRoot_Loaded(object sender,System.Windows.RoutedEventArgs e)
{
// Todo: Add event handler implementation here.
dispatcherTimer timer = new dispatcherTimer();
timer.Interval = new TimeSpan(0,1);//时间间隔为1s
timer.Tick +=new System.EventHandler(timer_Tick);
timer.Start();
}
private void timer_Tick(object sender,System.EventArgs e)
{
// Todo: Add event handler implementation here.
//首先获取是星期几 string week = DateTime.Now.DayOfWeek.ToString(); switch(week) { case "Monday": week = "星期一"; break; case "Tuesday": week = "星期二"; break; case "Wednesday": week = "星期三"; break; case "Thurday": week = "星期四"; break; case "Friday": week = "星期五"; break; case "Saturday": week = "星期六"; break; case "Sunday": week = "星期日"; break; } this.tbTime.Text = DateTime.Now.Year + " 年 " + DateTime.Now.Month + " 月 " + DateTime.Now.Day + " 日 "+ week +" "+ DateTime.Now.ToLongTimeString(); } }}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。