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


namespace Commands
{
    /// <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))
            {
                validationStatus.Text = "Musisz wprowadzić liczbę. W celu uzskania pomocy naciśnij F10.";
                numberField.BorderBrush = new SolidColorBrush(Colors.Red);
                //zdarzenie oznaczone jako obsłużone
                e.Handled = true;
            }
            else
            {
                validationStatus.Text = "";
                numberField.BorderBrush = _brush;
            }

        }
        
        private void HelpCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            
            if (validationStatus !=null && !validationStatus.Text.Equals(""))
            {
                e.CanExecute = true;
            }
            else
            {
                e.CanExecute = false;
            }
        }

        private void HelpExecuted(object sender, ExecutedRoutedEventArgs e)
        {

            MessageBoxResult res = MessageBox.Show("Liczby to na przykład 1, 2, 3");
        }
    }
}
