Digital Clock in WPF without Installing Digital Font

This is digital Clock in WPF without installing digital font.

MainWindow.xaml

  1. <Window x:Class="Digital_Clock.MainWindow"  
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
  4. Title="Current Time" Height="120" Width="290" ResizeMode="NoResize" WindowStyle="ToolWindow"Icon="1370614099_42192.ico">  
  5. <Grid>  
  6. <TextBlock Style="{StaticResource FontAwesome}" FontSize="80" Name="tbk_clock">  
  7.    <TextBlock.Foreground>  
  8.       <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">  
  9.          <GradientStop Color="Black" Offset="0.52"/>  
  10.          <GradientStop Color="White"/>  
  11.       </LinearGradientBrush>  
  12.    </TextBlock.Foreground>  
  13.      
  14.    <TextBlock.Background>  
  15.       <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">  
  16.          <GradientStop Color="Black" Offset="0"/>  
  17.          <GradientStop Color="White" Offset="1"/>  
  18.       </LinearGradientBrush>  
  19.    </TextBlock.Background>  
  20. </TextBlock>  
  21. </Grid>  
  22. </Window>  
MainWindow.xaml.cs
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Windows;  
  6. using System.Windows.Controls;  
  7. using System.Windows.Data;  
  8. using System.Windows.Documents;  
  9. using System.Windows.Input;  
  10. using System.Windows.Media;  
  11. using System.Windows.Media.Imaging;  
  12. using System.Windows.Navigation;  
  13. using System.Windows.Shapes;  
  14. namespace Digital_Clock  
  15. {  
  16. /// <summary>  
  17. /// Interaction logic for MainWindow.xaml  
  18. /// </summary>  
  19.   
  20. public partial class MainWindow : Window  
  21. {  
  22.    public MainWindow()  
  23.    {  
  24.       InitializeComponent();  
  25.       System.Windows.Threading.DispatcherTimer myDispatcherTimer = newSystem.Windows.Threading.DispatcherTimer();  
  26.       myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100); // 100 Milliseconds  
  27.       myDispatcherTimer.Tick += myDispatcherTimer_Tick;  
  28.       myDispatcherTimer.Start();  
  29.    }  
  30.    void myDispatcherTimer_Tick(object sender, EventArgs e)  
  31.    {  
  32.       tbk_clock.Text = DateTime.Now.ToString("hh:mm:ss");  
  33.    }  
  34. }  
  35. }  
App.xaml
  1. <Application x:Class="Digital_Clock.App"  
  2.   
  3.    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
  4.    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
  5.    StartupUri="MainWindow.xaml">  
  6.    <Application.Resources>  
  7.   
  8.       <Style x:Key="FontAwesome" TargetType="TextBlock">  
  9.   
  10.          <Setter Property="TextElement.FontFamily"Value="/Digital_Clock;Component/Fonts/#DS-Digital"/>  
  11.   
  12.       </Style>  
  13.   
  14.    </Application.Resources>  
  15. </Application>  
Output:

clock


Ebook Download
View all
Learn
View all