The main code is as follows:
<summary>///declares and defines the command. </summary>routedcommand Clearcommand = new RoutedCommand ("Clear", typeof (MainWindow));///<summary>// /Initialize command. Tri Youlai 2014-7-30 06:23:10///</summary>void Initializecommand () {//Set shortcut keys for the command. This. CLEARCOMMAND.INPUTGESTURES.ADD (New KeyGesture (KEY.C, Modifierkeys.alt)); Assigns a command to the command source. This.Button1.Command = this. Clearcommand; Specifies the command target. This.Button1.CommandTarget = this. Textboxa; Creates a command association and places it on a perimeter control. Commandbinding cb = new Commandbinding (); Cb.command = this. Clearcommand; Cb. CanExecute + = new Canexecuteroutedeventhandler (Cb_canexecute); Cb. Executed + = new Executedroutedeventhandler (cb_executed); THIS.STACKPANEL1.COMMANDBINDINGS.ADD (CB);} <summary>///executes the method when the command is delivered to the target. Tri Youlai 2014-7-30 06:27:16///</summary>///<param name= "sender" ></param>///<param name= "E" >< /param>void cb_executed (object sender, Executedroutedeventargs e) {this. Textboxa.clear (); e.handled = true;} <summary>///The method is called when the probe command is executable. Tri Youlai 2014-7-30 06:26:20///</summary>///<param name= "sender" ></param>///<param name= "E" >< /param>void Cb_canexecute (object sender, Canexecuteroutedeventargs e) {if (string. IsNullOrEmpty (this. Textboxa.text) = = true) E.canexecute = false; else E.canexecute = true; e.handled = true;}
WPF uses RoutedCommand custom commands