110,548
社区成员
发帖
与我相关
我的任务
分享
<Window x:Class="HostingWfInWpf.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="HostingWfInWpf"
Loaded="WindowLoaded"
>
<Grid Name="grid1">
</Grid>
</Window>
6.在代码编辑器中打开 Window1.xaml.cs。
7.将 Window1.xaml.cs 中的代码替换为以下代码。
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Forms;
namespace HostingWfInWpf
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void WindowLoaded(object sender, RoutedEventArgs e)
{
// Create the interop host control.
System.Windows.Forms.Integration.WindowsFormsHost host =
new System.Windows.Forms.Integration.WindowsFormsHost();
// Create the MaskedTextBox control.
MaskedTextBox mtbDate = new MaskedTextBox("00/00/0000");
// Assign the MaskedTextBox control as the host control's child.
host.Child = mtbDate;
// Add the interop host control to the Grid
// control's collection of child controls.
this.grid1.Children.Add(host);
}
}
}