Is there a simple Control that gives time and date in wpf c#

bish wakim
bish wakim used Ask the Experts™
I am using an application I have developed with WPF C# for teaching in class. I need a to build a simple control which I can put on the screen and have the date and time updated automatically.  
Please help!  
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
AshokSr. Software Engineer
Simplest control you can use is TextBlock.

Then use code to update it using String.Format() function.



In fact I need something simple.
May you tell me how can use code for this.
I need to retrieve day,month,year each time I enter my program. and have the time updated during the lesson. I rise my offer to 500 points.
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Reza RadConsultant, Trainer

use dispatchertimer for updating your datetime on a schedule
like below:

To add a bit on Reza_rad solution.
Add TextBlock in your WPF application and give it a name like x:Name="DateTimeTextBlock", then in code behind create DispatcherTimer like:

Place this code in your Initialize function:

var dt = new DispatcherTimer(); //(<- contains in System.Windows.Threading)
dt.Tick += new EventHandler(Tick);
dt.Interval = new TimeSpan(0,0,0,1000); //Set interval to 1 second

private void Tick(object sender, EventArgs e)
  DateTimeTextBlock.Text = DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss");

For more information on DateTime formating check:



Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial