Solved

Using a WinForms User Control inside WPF

Posted on 2010-08-15
12
756 Views
Last Modified: 2013-12-17
I am having trouble getting MapPoint into WPF:
http://www.experts-exchange.com/Microsoft/Development/Microsoft_Programming/WPF_and_Silverlight/Q_26403880.html

so I wonder if a WPF expert could simply attempt to use a simple WinForms User Control inside WPF instead.  This would alow me to rule out MapPoint.  It's be great if someone could create a user control with a a checkbox in it, as a WinForms user control.  Then try and get that into a WPF Grid.

Then tel me the steps to do this myself...

Thanks,
newbieweb
0
Comment
Question by:newbieweb
  • 7
  • 5
12 Comments
 
LVL 3

Expert Comment

by:bkokx
ID: 33440444
0
 

Author Comment

by:newbieweb
ID: 33440463
I was looking at that one, but I could not find the source code and decided it was too risky spending time where there is not proof it works.

Can u find the link to download the source?
0
 

Author Comment

by:newbieweb
ID: 33440488
I found a great example from Microsoft:
http://msdn.microsoft.com/en-us/library/ms750944.aspx

and there's source code.

I am just confused by this in the XAML file.

     <WindowsFormsHost Name="wfh"
                      DockPanel.Dock="Top"
                      Height="300">
       <mcl:MyControl1 Name="mc"/>
     </WindowsFormsHost>

I understand the WindowsFormsHost, but get confused about the definitions for "wfh", which matches its code behind usages.

Also "mcl:" and "mc"

Any comments on these?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 3

Expert Comment

by:bkokx
ID: 33440537
hi newbieweb:
Attached an example where the control (part of the code) is loaded at runtime
0
 

Author Comment

by:newbieweb
ID: 33440546
I don't understand your last post. (33440537)
0
 
LVL 3

Expert Comment

by:bkokx
ID: 33440549
Add here the same code but now with namespace reference so you can use it within xaml.
Note that "xmlns:me" refers to the application assembly itself.
0
 

Author Comment

by:newbieweb
ID: 33440561
Is "xmlns:me" for VB?
0
 
LVL 3

Accepted Solution

by:
bkokx earned 500 total points
ID: 33440573
Hi newbieweb, sorry the attachements were rejected because of the .XAML file extension ???
I will file a complaint, so be sure to rename a few files:
- app.xaml.txt to app.xaml
- MainWindow.xaml.txt to MainWindow.xaml
- Settings.settings.txt to Settings.settings

WpfAppWithWinFormsUC2.zip
0
 
LVL 3

Expert Comment

by:bkokx
ID: 33440596
In the example code the

        xmlns:me="clr-namespace:WpfApplication1"

is used to include the components (in this case UserControl1) of the defined assembly (this of the application itself that hosts the UserControl1). Of course you could include others aswell. For instance to include all standard winform controls you could add:

        xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
        xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"

For more info check: http://nayyeri.net/host-windows-forms-controls-in-wpf
0
 

Author Comment

by:newbieweb
ID: 33440604
Nice program!  That's just what I wanted.  Next I need to try and get a MapPoint control to be the User Control.

If you wanted to have some fun, here's the MapPoint free trial.  When I place the WinForms User Control into WPF it shows up blank?

http://www.mapforums.com/wpf-mappoint-control-7768.html




0
 

Author Closing Comment

by:newbieweb
ID: 33440608
Thanks.
0
 

Author Comment

by:newbieweb
ID: 33440620
Would you know how to have it include the MapPoint control that appears in the ToolBox?
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question