Digital Clock in WPF Application

In this article, I am trying to create a Digital Clock in WPF.
  • 3889

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=""      
        Title="Digital Clock"
        <src:ClockTicker1 x:Key="clock" />
        <Binding Source="{StaticResource clock}" Path="DateTime" />

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),
        Public Property DateTime() As DateTime
                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



I hope this article will help you to create a Digital Clock in WPF Application.


More Articles

© 2020 DotNetHeaven. All rights reserved.