Extensible Notepad made by WPF

Source: Internet
Author: User

Remember there was a WinForm. Using reflection to do the extensible notebook, idle to Nothing, then with WPF also made an extensible Notepad, the interface can be dynamically extended functionality, simpler, for reference:

The directory structure is as follows:

MainWindow.xaml main function interface, Functionexpand provides expansion interface;

The main function code is as follows:

private void Makefun ()
{
String location = this. GetType (). Assembly.location;
String dllpath = System.IO.Path.GetDirectoryName (location) + "\\plugs";

string[] Strdllpath = System.IO.Directory.GetFiles (DllPath, "*.dll");

foreach (var item in Strdllpath)
{
Assembly-Assembly.loadfile (item);

type[] types =. Getexportedtypes ();
Type Plugtype = typeof (IPlug);

foreach (Var t in types)
{
Determine if the Iplug interface is implemented
if (Plugtype.isassignablefrom (t))
{
Creating plug-in objects based on plug-in types
IPlug iplugobj = activator.createinstance (t) as IPlug;

Create a plug-in button
MenuItem menu = new MenuItem ();
Menu. Header = T.name;
THIS.EXPANDTOOL.ITEMS.ADD (menu);
Menu. Click + = Menu_click;
Menu. Tag = Iplugobj;
}

}

}

}

void Menu_click (object sender, RoutedEventArgs e)
{
MenuItem MenuItem = sender as MenuItem;
IPlug IPlug = Menuitem.tag as IPlug;
Tb_text.text = Iplug. Processtext (Tb_text.text);
}

The effect is as follows:

Now the code to share out, there are interested friends can study: source download

Reprint please specify from: Sparkling Lucky Star

Original address: Http://www.cnblogs.com/dongyang

If reproduced, please keep the original address. Thank you for your cooperation.

Extensible Notepad made by WPF

Related Article

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.