using System;
using System.Windows;
using System.Windows.Input;
using System.Diagnostics;
using System.Windows.Media;


namespace RoutedEvent_Validation
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        Brush _brush;
        public MainWindow()
        {
            InitializeComponent();
            _brush = numberField.BorderBrush;
        }


        private void NumberField_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            short val;
            if (!Int16.TryParse(e.Text, out val))
            {
                //wprowadzony znak to nie liczba
                validationStatus.Text = "Musisz wprowadzić liczbę...";
                numberField.BorderBrush = new SolidColorBrush(Colors.Red);
                //zdarzenie oznaczone jako obsłużone
                e.Handled = true;
            }
            else
            {
                validationStatus.Text = "";
                numberField.BorderBrush = _brush;
            }
        }

       
    }
}
