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 Ereignisse
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public static RoutedCommand ShowEvents = new RoutedCommand();
        int count;

        public MainWindow()
        {
            InitializeComponent();

            count = 0;

            // Registriere Behandlungsmethoden, die das bubbling MouseDown-Ereignis
            // auch dann abfangen, wenn es bereits behandelt wurde
            mainWindow.AddHandler(Window.MouseDownEvent, new MouseButtonEventHandler(mainWindowMouseDown), true);

            // Befehle für die Menübefehle
            CommandBinding cbNew = new CommandBinding(ApplicationCommands.New);
            cbNew.Executed += NewHandler;
            cbNew.CanExecute += NewExecuteHandler;

            CommandBinding cbShow = new CommandBinding(ShowEvents);
            cbShow.Executed += ShowHandler;

            this.CommandBindings.Add(cbNew);
            this.CommandBindings.Add(cbShow);
        }

        // Behandlungsmethode für PreviewMouseDown
        private void mainWindow_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            textBox1.Text += "\n " + count++ + " Ereignis: PreviewMouseDown    Sender: " + sender.ToString();
        }
        private void dockPanel1_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            textBox1.Text += "\n " + count++ + " Ereignis: PreviewMouseDown    Sender: " + sender.ToString();
        }
        private void grid1_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            textBox1.Text += "\n " + count++ + " Ereignis: PreviewMouseDown    Sender: " + sender.ToString();
        }
        private void btnShow_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            textBox1.Text += "\n " + count++ + " Ereignis: PreviewMouseDown    Sender: " + sender.ToString();
        }


        // Behandlungsmethode für Click
        private void mainWindow_Click(object sender, RoutedEventArgs e)
        {
            textBox1.Text += "\n " + count++ + " Ereignis: ButtonBase.Click    Sender: " + sender.ToString();
        }
        private void dockPanel1_Click(object sender, RoutedEventArgs e)
        {
            textBox1.Text += "\n " + count++ + " Ereignis: ButtonBase.Click    Sender: " + sender.ToString();
        }
        private void grid1_Click(object sender, RoutedEventArgs e)
        {
            textBox1.Text += "\n " + count++ + " Ereignis: ButtonBase.Click    Sender: " + sender.ToString();
        }
        private void btnShow_Click(object sender, RoutedEventArgs e)
        {
            textBox1.Text += "\n " + count++ + " Ereignis: Click    Sender: " + sender.ToString();
        }


        // Behandlungsmethode für MouseDown und MouseUp
        private void mainWindowMouseDown(object sender, MouseButtonEventArgs e)
        {
            textBox1.Text += "\n " + count++ + " AddedHandler-Ereignis: MouseDown    Sender: " + sender.ToString();
        }


        // Behandlungsmethoden für die Menübefehle
        private void NewHandler(object sender, ExecutedRoutedEventArgs e)
        {
            textBox1.Text = "";
            count = 0;
        }
        private void NewExecuteHandler(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = (textBox1.Text.Length > 0);
        }

        private void ShowHandler(object sender, ExecutedRoutedEventArgs e)
        {
            textBox1.Text += "\n " + count++ + " Ereignis: ShowEvents-Befehl    Sender: " + sender.ToString();
        }


    }
}
