Digital Clock in WPF Application
In this article, I am trying to create a Digital Clock in WPF.
A Digital clock is a modern and simple standalone desktop clock which used for displaying the current date and time.
Source code for Digital Clock
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src="clr-namespace:WpfApplication1.WpfApplication12.DigitalClock"
Title="Digital Clock"
SizeToContent="WidthAndHeight">
<Window.Resources>
<src:ClockTicker1 x:Key="clock" />
</Window.Resources>
<Window.Content>
<Binding Source="{StaticResource clock}" Path="DateTime" />
</Window.Content>
</Window>
Code for VB Window
Imports System
Imports System.Windows
Import System.Windows.Threading
Namespace WpfApplication1.DigitalClock
Class ClockTicker1
Inherits DependencyObject
Public Shared DateTimeProperty As DependencyProperty = DependencyProperty.Register("DateTime", GetType(DateTime),
GetType(ClockTicker1))
Public Property DateTime() As DateTime
Get
Return CType(GetValue(DateTimeProperty), DateTime)
End Set
End Property
Public Sub New()
Dim timer As New DispatcherTimer()
AddHandler timer.Tick, AddressOf TimerOnTick
timer.Interval = TimeSpan.FromSeconds(1)
End Sub
Private Sub TimerOnTick(ByVal sender As Object, ByVal args As EventArgs)
DateTime = Date.Now
End Sub
End Class
End Namespace
A simple Digital Clock
CONCLUSION
I hope this article will help you to create a Digital Clock in WPF Application.