【发布时间】:2013-09-09 20:56:49
【问题描述】:
【问题讨论】:
【问题讨论】:
关于这个主题有很多可用的资源。以下是从简单的 Google 搜索返回的一些:
我将解释第一个链接,因为它相当简单且易于管理。它实际上没有多少代码。
首先您需要添加对以下程序集的引用:
然后创建一个网格(在本例中名为 Grid1)。
这是代码隐藏:
private void Window_Loaded(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);
}
您所做的只是实例化WindowsFormsHost,然后添加一个名为mtbDate 的子控件。实例化您自己的控件并使用相同的方法添加它。然后像往常在 Win Forms 中一样操作它。
然后在类的顶部添加一个 using:
using System.Windows.Forms;
希望对你有帮助。
【讨论】: