In my previous article, I demonstrated how to host a WPF control within a windows application and in this tutorial, I will show how to host a windows form control within a WPF application.
In my previous article, I demonstrated how to host a WPF control within a windows application and in this tutorial I will show how to host a windows form control within a WPF application. To do so, I invite you to follow this walkthrough.
Walkthrough:
<my:WindowsFormsHost Margin="18,20,38,73" Name="windowsFormsHost1">
<Window x:Class="myWpfApplication.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wf="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
Title="Window1" Height="300" Width="300" xmlns:my="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
Loaded="Window_Loaded">
<Grid>
<WindowsFormsHost Height="100" Margin="39,27,39,0" Name="windowsFormsHost1" VerticalAlignment="Top" >
</WindowsFormsHost>
</Grid>
<wf:ElementHost BackColor="Beige">
<Button Background="Bisque" Margin="39,27,39,27" Click="Button_Click">Click me please!</Button>
</wf:ElementHost>
private void Button_Click(object sender, RoutedEventArgs e)
{
System.Windows.Forms.MessageBox.Show("My parent is the hosted window form","Message");
That's it.
Good Dotneting!!!
Programming XAML