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.Diagnostics;

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

        private void buttonsGrid_Click(object sender, RoutedEventArgs e)
        {
            e.Handled = gridClickCheckBox.IsChecked.Value;
            ShowMethodName();
        }

        private void buttonsGrid_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            // This is the first event in the series. Clear the result TextBox.
            resultsTextBox.Clear();

            e.Handled = gridPreviewCheckBox.IsChecked.Value;
            ShowMethodName();
        }

        private void buttonsStackPanel_Click(object sender, RoutedEventArgs e)
        {
            e.Handled = stackPanelClickCheckBox.IsChecked.Value;
            ShowMethodName();
        }

        private void buttonsStackPanel_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled = stackPanelPreviewCheckBox.IsChecked.Value;
            ShowMethodName();
        }

        private void Button1_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled = buttonPreviewCheckBox.IsChecked.Value;
            ShowMethodName();
        }

        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            e.Handled = buttonClickCheckBox.IsChecked.Value;
            ShowMethodName();
        }

        private void Button2_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled = buttonPreviewCheckBox.IsChecked.Value;
            ShowMethodName();
        }

        private void Button2_Click(object sender, RoutedEventArgs e)
        {
            e.Handled = buttonClickCheckBox.IsChecked.Value;
            ShowMethodName();
        }

        private void Button3_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled = buttonPreviewCheckBox.IsChecked.Value;
            ShowMethodName();
        }

        private void Button3_Click(object sender, RoutedEventArgs e)
        {
            e.Handled = buttonClickCheckBox.IsChecked.Value;
            ShowMethodName();
        }

        // Record the name of the method that called this one.
        private void ShowMethodName()
        {
            resultsTextBox.AppendText(
                new StackTrace(1).GetFrame(0).GetMethod().Name + '\n');
        }
    }
}
