PrivateDispatcherTimer DispatcherTimer; PublicMainWindow () {InitializeComponent (); DispatcherTimer=NewSystem.Windows.Threading.DispatcherTimer (); //events that occur when the interval is overDispatchertimer.tick + =NewEventHandler (showcurrenttime); Dispatchertimer.interval=NewTimeSpan (0,0,0,1); Dispatchertimer.start (); } Public voidShowcurrenttime (Objectsender, EventArgs e) { //Get Week//This.tBlockTime.Text = DateTime.Now.ToString ("dddd", New System.Globalization.CultureInfo ("ZH-CN")); //This.tBlockTime.Text + = "\ n"; //acquired date//This.tBlockTime.Text = DateTime.Now.ToString ("Yyyy:MM:dd"); //yyyy mm month DD Day//This.tBlockTime.Text + = "\ n"; //get time-Division seconds This. Tblocktime.text = DateTime.Now.ToString ("yyyy-mm-dd HH:mm:ss dddd"); }
<Name= "Tblocktime" FontSize= " grid.column" = "1" horizontalalignment= "Right" Foreground= "Green" />
Operating effect:
WPF dynamic time (electronic table)