2

I've downloaded this user-control which is developed in WPF, but I would like to know if exists the chance to use the dll in WF (the dll where is the user-control), of course sadly if I try to add the control in the ToolBox doesn't appears for WF projects, only for WPF.

I've found this article in MSDN that describes that WinForms controls can loaded in WPF projects

· Hosting a Windows Forms Control in WPF

So, it can be done the reversed thing to use an WPF control in a WF project?

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • errr... thanks but this question does not have an answer. I didn't knew the info that yu've provided but they are only explaining how to use "ElementHost" to add a control, yes, but creating it in XAML, a WPF project control (uncompiled), I'm asking about how to add the compiled dll to use the user-contorl that is inside that dll, in case that could be possible. – ElektroStudios Aug 18 '14 at 00:07
  • @user2864740 yes you are right, sorry my english is not very good sometimes I do not emphasize in the proper way, I've solved it by referencing the dll, but there is no way to use it in design-time?, feel free to write an answer 'cause your suggestion solved my problem, but if you could help me to know whether I could manage the control at design-time in the UI i will appreciate it, I've seen that this can be done with "ElementHost" does not detect my referenced dll to do that, thanks – ElektroStudios Aug 18 '14 at 00:17
  • Also I noticed that the WPF control is not recognized a a "Control" type so I can't add it manualy in the code... – ElektroStudios Aug 18 '14 at 00:22
  • WPF controls inherit from `System.Windows.Controls.Control` while WinForms inherit from `System.Windows.Forms.Control` - so while they are both Controls, they are derived from *different* "Control" classes. Thus in a mixed project it may be confusing to simply use `Control` and I would recommend using `Forms.Control` and/or `Controls.Control` to disambiguate the types. – user2864740 Aug 18 '14 at 00:24
  • The method `Form.Controls.Add()` does not accept a `System.Windows.Controls.Control`, this should not be a problem but yes its a problem 'cause even selecting/checking the WPF control in the menu of the toolbox (in the WPF Components tab) it does not appear in my WinForms toolbox so I don't know how to procceed – ElektroStudios Aug 18 '14 at 00:27
  • See http://tech.pro/tutorial/799/wpf-tutorial-using-wpf-in-winforms - after referencing the project and adding an ElementHost, set the "[Select] Hosted Content" property of the ElementHost itself. – user2864740 Aug 18 '14 at 00:34
  • In Resume: I've referenced the WPF dll and the WF project compiled well, in the ToolBox menu the WPF control was selected by default but it does not appear in my WF toolbox, so I can't find the way to add this control in the UI 'case also the `Form.Controls.Add()` fails to add the control throwing a wrong type exception. I've tried to convert the type and rebuild the project, no way. – ElektroStudios Aug 18 '14 at 00:35
  • @user2864740 yes I understood that point but I'm not referencing the project I've referenced the compiled dll, it is full necessary to also reference the project? 'cause in other WPF controls I don't have the source code. – ElektroStudios Aug 18 '14 at 00:36
  • You can reference the Project *or* the DLL, but it must be referenced. – user2864740 Aug 18 '14 at 00:38
  • I've referenced the WPF dll and after that I've compiled the WF project to apply changes in the elementHost, but as I'm trying to explain the WPF control does not appear inside the dropdownlist of the elementhost. If I upload the project you could revise it for faults or something?, thanks for your help – ElektroStudios Aug 18 '14 at 00:40
  • Here is the WinForms project if someone could verify what is wrong, it has the WPF dll referenced (inside the Bin folder): http://www.mediafire.com/download/ied1g784u8532n8/WindowsApplication8.rar – ElektroStudios Aug 18 '14 at 00:52

1 Answers1

1

Just set the .Child property to your WPF control.

enter image description here

Colin Smith
  • 12,375
  • 4
  • 39
  • 47