XAML
<Grid Name="grid1">
</Grid>
Code Behind
private void Window_Loaded(object sender, RoutedEventArgs e)
{
// Cria um host para windows forms
System.Windows.Forms.Integration.WindowsFormsHost host =
new System.Windows.Forms.Integration.WindowsFormsHost();
// cria o componente de máscara do windows forms
MaskedTextBox mtbDate = new MaskedTextBox("00/00/0000");
// adiciona o MaskedTextBox no host
host.Child = mtbDate;
// adiciona o host na grid do WPF
this.grid1.Children.Add(host);
}
Need to add
using System.Windows.Forms;
Source: https://msdn.microsoft.com/pt-br/library/ms751761(v=vs.110). aspx
My practical example
I already used Windows Forms Host to use Reportviewer in WPF
<mah:MetroWindow x:Class="Capacitor.WPF.View.Relatorios.TelaRelatorio"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:view="clr-namespace:Capacitor.WPF.View"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:rv="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms"
BorderBrush="{DynamicResource AccentColorBrush}"
Title="Relatório" Height="1101.88" Width="814.286" WindowState="Maximized">
<Grid>
<WindowsFormsHost>
<rv:ReportViewer x:Name="reportViewer"/>
</WindowsFormsHost>
</Grid>
</mah:MetroWindow>
I recommend creating a mask Controlle in WPF even, have many examples on the internet, to avoid dependencies with Windows Forms. For example, if you use a styling with Styles in WPF, you will most likely not be able to apply these styles to these guys.
But as I needed to use Reportviewer, I had to appeal to Windowsformshost. However I felt it slowed down this screen.
good response...
– Marco Souza