The UserControl of WPF in the WinForm of "the Handsome Hedgehog class"

Source: Internet
Author: User

Today is ready to do a login interface, want to use WPF to make a more beautiful interface, all in the WinForm project to join the WPF user control, the process is as follows, Frmlogin is the WinForm interface, is the parent form, The UserControl of Login.xaml WPF is a subform,

First open the Frmlogin design interface, in the left side of the toolbar to find the drag to the interface, and the dock is set to fill, in fact, let ElementHost fill the entire interface. Then add the following code in the Frmlogin:

1 protected Override voidOnLoad (EventArgs e)2         {                        3             if(!DesignMode)4             {5                 varLogin =NewLogin ( This);6Elementhost1.child =login; 7             }8             9             Base. OnLoad (e);Ten}

Here is an example, I am in this UserControl click Login, hide themselves at the same time, also need to hide the parent form, it will hide the frmlogin, so I would like to set a property in the parent form code: myopacity is readable and writable. The code is as follows:

 Public Doublemyopacity{Get{return  This. Opacity; }       Set{ This. opacity=value;}}protected Override voidOnLoad (EventArgs e) {if(!DesignMode) {              varLogin =NewLogin ( This);//Here the parent form is passed to the subform login to Elementhost1.child=login; }                     Base. OnLoad (e);}

Then add the following in the subform code:

 PublicLogin (frmlogin frm): This()//by using the constructor to fetch Frmlogin, which is the parent form, to { This. Frmlogin =frm; Trepository=Newt_huntersrepository ();}Private voidBtnstart_onclick (Objectsender, RoutedEventArgs e) {            if(Trepository.login (Username.text, Userpassword.text)) {Form1 Form1=NewForm1 (); Form1.                Show ();  This. Opacity =0; Change your transparency frmlogin.myopacity=0; Change the transparency of the parent form here}Else{MessageBox.Show ("Check your username and password! ","system prompt:"); }        }

Simple interface, green part for WPF UserControl, red for WinForm form, click Login successful, both will be hidden.

Reprint Please specify: "Handsome hedgehog classroom", if you have any questions QQ contact: 363608715

The UserControl of WPF in the WinForm of "the Handsome Hedgehog class"

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.