Adding User Control (WPF) to Panel in Windows Form c# -
i'm making outlook add in when user launches add in, windows form comes up. within windows form, dynamically adding user controls based on user input.
the problem i'm having adding control programmatically. works fine if add standard textbox
when add user control, below exception;
the best overloaded method match 'system.windows.forms.control.controlcollection.add(system.windows.forms.control)' has invalid arguments
cannot convert 'outlookaddin.controls.rform' 'system.windows.forms.control'
i tried casting control usercontrol
new exceptions arose.
main form:
using system.windows.forms; namespace outlookaddin { public partial class main : form { public main() { initializecomponent(); } private void lblreactivemaintenance_click(object sender, eventargs e) { outlookaddin.controls.rform reactivemaintform = new outlookaddin.controls.rform(); reactivemaintform.name = "rform"; pnlmain.controls.add(reactivemaintform); } } }
user control:
namespace outlookaddin.controls { /// <summary> /// interaction logic rform.xaml /// </summary> public partial class rform : usercontrol { public rform() { initializecomponent(); } } }
you should able use elementhost control wrap wpf control. see https://msdn.microsoft.com/en-us/library/system.windows.forms.integration.elementhost(v=vs.110).aspx.
private void lblreactivemaintenance_click(object sender, eventargs e) { outlookaddin.controls.rform = new outlookaddin.controls.rform(); reactivemaintform.name = "rform"; elementhost2.child = reactivemaintform; }
Comments
Post a Comment