• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 767
  • Last Modified:

Using a WinForms User Control inside WPF

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
newbieweb
Asked:
newbieweb
  • 7
  • 5
1 Solution
 
newbiewebAuthor Commented:
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
 
newbiewebAuthor Commented:
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
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
bkokxCommented:
hi newbieweb:
Attached an example where the control (part of the code) is loaded at runtime
0
 
newbiewebAuthor Commented:
I don't understand your last post. (33440537)
0
 
bkokxCommented:
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
 
newbiewebAuthor Commented:
Is "xmlns:me" for VB?
0
 
bkokxCommented:
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
 
bkokxCommented:
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
 
newbiewebAuthor Commented:
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
 
newbiewebAuthor Commented:
Thanks.
0
 
newbiewebAuthor Commented:
Would you know how to have it include the MapPoint control that appears in the ToolBox?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now