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

bish wakim
bish wakim used Ask the Experts™
on
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!  
Comment
Watch Question

Do more with

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

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

HTH
Ashok

Author

Commented:
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.
Thanks
CompTIA Network+

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

Reza RadConsultant, Trainer

Commented:
use dispatchertimer for updating your datetime on a schedule
like below:
http://stackoverflow.com/questions/479376/wpf-net-best-way-to-trigger-an-event-every-minute

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
dt.Start();

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: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

Author

Commented:
Thanks

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