WPF uses RoutedCommand custom commands

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.