This is digital Clock in WPF without installing digital font.
MainWindow.xaml
- <Window x:Class="Digital_Clock.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="Current Time" Height="120" Width="290" ResizeMode="NoResize" WindowStyle="ToolWindow"Icon="1370614099_42192.ico">
- <Grid>
- <TextBlock Style="{StaticResource FontAwesome}" FontSize="80" Name="tbk_clock">
- <TextBlock.Foreground>
- <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
- <GradientStop Color="Black" Offset="0.52"/>
- <GradientStop Color="White"/>
- </LinearGradientBrush>
- </TextBlock.Foreground>
-
- <TextBlock.Background>
- <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
- <GradientStop Color="Black" Offset="0"/>
- <GradientStop Color="White" Offset="1"/>
- </LinearGradientBrush>
- </TextBlock.Background>
- </TextBlock>
- </Grid>
- </Window>
MainWindow.xaml.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace Digital_Clock
- {
-
-
-
-
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- System.Windows.Threading.DispatcherTimer myDispatcherTimer = newSystem.Windows.Threading.DispatcherTimer();
- myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100);
- myDispatcherTimer.Tick += myDispatcherTimer_Tick;
- myDispatcherTimer.Start();
- }
- void myDispatcherTimer_Tick(object sender, EventArgs e)
- {
- tbk_clock.Text = DateTime.Now.ToString("hh:mm:ss");
- }
- }
- }
App.xaml
- <Application x:Class="Digital_Clock.App"
-
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- StartupUri="MainWindow.xaml">
- <Application.Resources>
-
- <Style x:Key="FontAwesome" TargetType="TextBlock">
-
- <Setter Property="TextElement.FontFamily"Value="/Digital_Clock;Component/Fonts/#DS-Digital"/>
-
- </Style>
-
- </Application.Resources>
- </Application>
Output: