using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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;

using System.Windows.Threading;

namespace WpfBlinkingLabel
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        // Create a timer.
        private DispatcherTimer TheTimer;
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            TheTimer = new DispatcherTimer();
            TheTimer.Tick += TheTimer_Tick;
            TheTimer.Interval = new TimeSpan(0, 0, 0, 0, 500);
            TheTimer.Start();
        }

        // The timer's Tick event.
        private bool BlinkOn = false;
        private void TheTimer_Tick(object sender, EventArgs e)
        {
            if (BlinkOn)
            {
                timerLabel.Foreground = Brushes.Red;
                timerLabel.Background = Brushes.LightGreen;
            }
            else
            {
                timerLabel.Foreground = Brushes.LightGreen;
                timerLabel.Background = Brushes.Red;
            }
            BlinkOn = !BlinkOn;
        }
    }
}
