Can not Convert System.Windows.Controls to System.Windows.Forms.Controls [modified]
-
Can any one Help I have created one Panel Control(System.Windows.Forms) using wpf window application and create one user control using Windows Control Library. I want to add the usercontrol in Panel I have tried the following code
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration" xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" Title="Sivam" Height="300" Width="300" Loaded="Form_Load"> grid> windowsformshost margin="7.37,6.72333333333333,48,22"> wf:panel height="50" x:name="panel1" text="Prompt" xmlns:wf="#unknown" /> /windowsformshost> /grid> /window>;
private void Form_Load(object Sender, EventArgs e) { UserControl1 uc1 = new UserControl1(); **panel1.Controls.Add(uc1);** //System.Windows.Forms.Integration.ElementHost host = new System.Windows.Forms.Integration.ElementHost(); //UserControl1 uc1 = new UserControl1(); //host.Controls.Add(uc1); //panel1.Controls.Add(host); }
But I got the Error Convert System.Windows.Controls to System.Windows.Forms.Controls Thanks, Sivamodified on Thursday, September 11, 2008 9:52 AM
-
Can any one Help I have created one Panel Control(System.Windows.Forms) using wpf window application and create one user control using Windows Control Library. I want to add the usercontrol in Panel I have tried the following code
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration" xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" Title="Sivam" Height="300" Width="300" Loaded="Form_Load"> grid> windowsformshost margin="7.37,6.72333333333333,48,22"> wf:panel height="50" x:name="panel1" text="Prompt" xmlns:wf="#unknown" /> /windowsformshost> /grid> /window>;
private void Form_Load(object Sender, EventArgs e) { UserControl1 uc1 = new UserControl1(); **panel1.Controls.Add(uc1);** //System.Windows.Forms.Integration.ElementHost host = new System.Windows.Forms.Integration.ElementHost(); //UserControl1 uc1 = new UserControl1(); //host.Controls.Add(uc1); //panel1.Controls.Add(host); }
But I got the Error Convert System.Windows.Controls to System.Windows.Forms.Controls Thanks, Sivamodified on Thursday, September 11, 2008 9:52 AM
It looks to me like you either have a namespace issue, or you're trying to add the wrong type somewhere. For example, if UserControl1 is a WPF control (which it appears to be), you can't add that to a windows forms panel. Use the Canvas class instead. The windows forms host is for hosting windows forms controls inside a WPF window.
“Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’) Built with home-grown CodeProject components! -”-”-