Implementing the dynamic response of a button

Source: Internet
Author: User

Different logic is implemented by pressing a different button

But with the same code:

1 usingSystem.Reflection;2 3 namespaceValuablebook4 {5     /// <summary>6     ///Interaction logic for Item.xaml7     /// </summary>8      Public Partial classItem:window9     {Ten          PublicItem () One         { A InitializeComponent (); -         } -  the         Private voidButton_Click (Objectsender, RoutedEventArgs e) -         { -Button cmd = E.originalsource asButton; -Type type = This. GetType (); +Assembly Assembly =type. Assembly; -Window win = (window) assembly. CreateInstance (type. Namespace +"."+cmd. TAG); + win. ShowDialog (); A  at         } -     } -}

button at the front desk

1    <stackpanel margin="5" button.click="button_click"> 2             <button content="MainWindow" tag="MainWindow" ></Button>3         </StackPanel>

An example on MSDN:

1 usingSystem;2 usingSystem.Reflection;3 usingcontoso.libraries;4 5 namespacecontoso.libraries6 {7     Public class Person8    {9       Private string_name;Ten  One        PublicPerson () A       { } -  -        PublicPerson (stringname) the       { -           This. _name =name; -       } -  +        Public stringName -{Get{return  This. _name;} +         Set{ This. _name =value;} } A  at        Public Override stringToString () -       { -          return  This. _name; -       } -    } - } in  -  Public classExample to { +     Public Static voidMain () -    { theAssembly Assem =typeof(person). Assembly; *Person P = (person) Assem. CreateInstance ("Contoso.Libraries.Person"); $       if(! (p = =NULL)) {Panax NotoginsengP.name ="John"; -Console.WriteLine ("instantiated a {0} object whose value is ' {1} '", the P.gettype (). Name, p); +       } A       Else { theConsole.WriteLine ("Unable to instantiate a person object."); +       }    -    } $ } $ //The example displays the following output: - //instantiated a person object whose value is ' John '

Implementing the dynamic response of a button

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.