点击按钮把窗体关闭 把页面的控件传递到自定义指令的函数中
FindAncestor 找到该组件的祖先元素
         AncestorType={x:Type Window} 祖先元素类型为window
          CommandParameter 自定义指令传递参数
 
自定义指令
public class MyCommand : ICommand
{
    public event EventHandler CanExecuteChanged;
    public bool CanExecute(object p)
    {
        return true;
    }
    public void Execute(object p)
    {
        var window = p as Window;
        if (window != null)
        {
            window.Close();
        }
    }
} public MainWindow()
  {
      InitializeComponent();
      M1 = new MyCommand();
      this.DataContext = this;
     //把指令封装公共类里面
      //M1 = new CMD();
      //this.DataContext = this; 
  }
  public MyCommand M1 { get;set; }
  //public CMD M1 { get; set; } 把指令封装公共类里面









