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 DelegateSample
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        //TODO: 1.声明MyDelegate变量


        public MainWindow()
        {
            InitializeComponent();
        }

        //TODO: 2.根据MyDelegate规格建立问好的方法 


        private void btnExecute_Click(object sender, RoutedEventArgs e)
        {
            string data = "";
            if (handler != null)
            {
                //TODO: 6.通过handler委派对象触发方法运行

            }

            tbResult.Text = data;
        }

        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            //取出被选取的CheckBox控件
            CheckBox chk = (CheckBox)sender;

            //TODO: 4.取出CheckBox控件对应的MyDelegate委派对象


            //TODO: 5.根据CheckBox控件选取状态，将方法位置参考加入handler委派对象

        }

        private void CheckBox_UnChecked(object sender, RoutedEventArgs e)
        {
            //取出被选取的CheckBox控件
            CheckBox chk = (CheckBox)sender;

            //取出CheckBox控件对应的MyDelegate委派对象
            MyDelegate d = (MyDelegate)chk.Tag;

            //根据CheckBox控件选取状态，将方法位置参考从handler委派对象移除
            handler -= d;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //TODO: 3.将方法的位置参考纪录到对应的CheckBox控件中

        }


    }
}

