Reputation: 1828
I need to add a Windows form User Control (Barcode_Scanner.cs) to a WPF View (MainWindow.xaml)
Is there a simple way to do this? Any help would be appreciated.
Upvotes: 1
Views: 2547
Reputation: 43596
You can host Windows.Forms
controls using the WPF WindowsFormsHost
element.
Example:
<Window x:Class="WpfApplication10.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:winforms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns:myControls="clr-namespace:MyContromNamespace;assembly=MyContromNamespace"
Title="MainWindow" Height="195" Width="191" Name="UI">
<Grid>
<WindowsFormsHost>
<winforms:Button Text="StackOverflow" />
</WindowsFormsHost>
<WindowsFormsHost>
<myControls:MyUserControl />
</WindowsFormsHost>
</Grid>
</Window>
Result:
Upvotes: 3
Reputation: 10143
you can do it with WindowsFormsHost
So the first thing that we need to do (after creating a new WPF project) is add a few references. You can do this by by right-clicking on the references folder in the solution explorer, and choosing "Add Reference":
Then you will get a dialog like this:
and so on wpf-tutorial-using-winforms-in-wpf
Upvotes: 1