Canvas control is not available in Windows form application? - wpf

WPF Canvas control is not available in Windows form application. Am using Visual Studio 2010. Framework 4.0. Is there way to add these controls to VS2010 toolbox?

You can create a WPF Usercontrol containing the Canvas control and then host it in an ElementHost control in winforms. Details of how to do it here.
You can then add that final control to the toolbox. More details on how to do can be found on this answer.

Related

WPF datagrid control

what to do if data grid control was not available in WPF component visual studio 2008
i ll try to add control from wpf component but there are no data grid control available in the list.
If you are using WPF 3.5, you need to install WPF Toolkit to get DataGrid control.
However, with WPF 4.0, microsoft introduce DataGrid under System.Windows.Controls (PresentationFramework.dll) assembly so that it can be used just like other controls without referring to WPFToolkit.

Winforms toolbox tools for WPF

I'm new to WPF and I'm wondering is there anyway to have elements from Winforms toolbox in WPF. I mean the Winforms toolbox has a lot of elements and they're not present in WPF toolbox. for example something like PerformanceCounter in Winforms toolbox is not found in WPF toolbox.
thanks in advance
There are some controls that didn't get represented in WPF, but you can use WindowsFormsHost. As the name indicates, it's purpose is to host the Windows Forms elements.
Walkthrough: Hosting a Windows Forms Control in WPF
I would add that things like PerformanceCounter you can use in code, rather than placing it on a form. Other elements which do have a UI purpose can be placed inside a WindowsFormsHost control. I do this with ReportViewer -- it's a Windows Forms control that has no WPF equivalent.

Can the controls in the toolbox be used in both Winform and WPF application?

If not, how can I know which controls are used in winforms, which controls are used in WPF?
If you develop a WinForms application, WPF controls are not shown in your toolbox, and vice versa.
If you want to use a WinForms control in a WPF application anyway, there's the WindowsFormsHost WPF control for that.
For hosting a WPF control in a Windows Forms app, you can use the System.Windows.Forms.Integration.ElementHost control.
The toolboxes already filter what controls you can use depending on whether you have created a Win Form or a WPF application project.

how to add a WPF dialog to a Winforms project

I am using Visual Studio 2008 targeting .net 3.5 framework. I need to add a WPF dialog to a Winforms project. I was thinking that by adding reference to PresentationCore, PresentationFramework and WindowsBase.dll and copying a WPF dialog from a test WPF project to the WinForms project in question should do the trick, but after that when I try to open in designer a WinForms dialog studio just crashes and closes.
So basically the question is how to add a WPF dialog to a WinForms project?
Thanks
Create the dialog as a WPF UserControl Library. Add it to the Windows Form application by using Project->Add Existing Item. Add an ElementHost component to the Windows Forms form. Set the HostedContent of the ElementHost to the WPF User Control.
This link may help you:
http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.elementhost.aspx

Mixing WPF with a WinForm application?

My fairly large WinForm application needs a GUI overhaul, but I can't afford to do it all at once. I need to know if I can slowly add WPF into it, and if so, how?
Can I add WPF dialogs?
Can I add WPF 'panels' within a WinForm so that I can embed WPF elements?
EDIT
Can I do the opposite and put WinForm dialogs in my WPF application?
Yes, you can host WPF controls in your WinForms applications:
Walkthrough: Hosting a 3-D WPF Composite Control in Windows Forms
Walkthrough: Hosting a Composite WPF Control in Windows Forms
Yep, I've successfully mixed winforms and WPF. I even managed to add WPF windows to win32 apps, changed this app to a dll and used a WPF app to show win32 windows which show WPF windows.
To host WPF windows in WinForm or win32 apps you will need this line befor you .Show() your WpfWindow:
System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(myWpfWindow);
See http://msdn.microsoft.com/en-us/library/aa348549.aspx
You can use the ElementHost control found in the System.Windows.Forms.Integration namespace. You will need a reference to the WindowsFormsIntegration assembly (in WindowsFormsIntegration.dll)
This control is an empty container into which you can put WPF controls e.g.
myElementHost.Child = someWpfControl;
You can find it in your toolbox and drag and drop it onto a winform like any other control;

Resources