WPF user control how to display on the form

I know the current approach has been successfully implemented in two.

method 1:

Dragged into a target ElementHost control in the form, and then in the code behind the code by way of a custom WPF user control is added to elementHost control,

ex:

1 UserControl1 wpf = new UserControl();
2 elementHost1.Child = wpf;

 

Method 2:

Good design after their WPF user control (wpfUserControl), then add a normal user control (UserControl, the suffix .cs) in the project, and then drag a ElementHost control (elementHost1) in the UserControl, select elmentHost1 controls, this when the upper right corner of the control will be a triangle symbol, click on the triangle, you can choose a custom WPF user control from the options in front of the jump.

If you want to add a custom WPF user control on the form, this time to drag a ElementHost control on the form, click on the triangle top right corner of the control, you can directly add WPF user control to the form, rather than then you need to write code behind.

 

Supplementary: WPF user control which adds runtime solutions picture does not show the picture

Pictures do not run out of the picture because of the "Build Action" attribute set to "content" of the property into the "Resource" on the line.

Method: select the target picture in the catalog Solution Explorer, the property page will then appear under "Build Action" property into a "Resource" can (or right-click and select "Properties" to modify).

Guess you like

Origin www.cnblogs.com/long612-/p/11469668.html