0

I have a WinForms User Control (a toolbar) which i would like to add on a WPF user Control, is there any way to do this?

like i want a WinForms User Control (the toolbar) along with other WPF Controls (datagrid) on a new WPF User Control

I saw a couple of samples that show Windows Forms hosted in a WPF Control. But that is not what i want to see.

6
  • You want to use a WPF control in a WinForms application, right? Commented Feb 2, 2012 at 19:36
  • By "Windows .NET User Control" do you mean a WinForms UserControl, or a WPF UserControl? Commented Feb 2, 2012 at 19:52
  • @Joe White - A win forms User Control. Commented Feb 2, 2012 at 20:30
  • @iaimtomisbehave : nope the other way, a windows user control in a WPF user control Commented Feb 2, 2012 at 20:31
  • 1
    "But that is not what i want to see" Sounds like it's exactly what you want to see: hosting WinForms in a WPF parent. Can you explain why those samples don't solve your problem? Commented Feb 2, 2012 at 23:42

2 Answers 2

1

This is pretty easy to pull off. There is a handy little thing known as WindowsFormHost all you have to do is declare it in your control's XAML, and nest your forms control inside of it, like so:

<UserControl>
...
<Grid>
  <WindowsFormsHost>
    <forms:MyFormsToolbarControl/>
  </WindowsFormHost>
</Grid>

...

WindowsFormHost lives inside of the normal WPF toolbox so it shouldn't be hard to locate. Meanwhile there is an example of how to produce the equivalent XAML in code at this location...

http://msdn.microsoft.com/en-us/library/ms751761.aspx

Sign up to request clarification or add additional context in comments.

Comments

0

You can check out my answer to a similar question here:

WPF hosting a WinForm, Tab Navigation problems

This will also show you how to fix a tabbing issue with windows controls that are sitting inside wpf views.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.