问题描述
作为一个短期的解决办法我试图干扰Windows窗体用户控件变成一个WPF应用程序。我看到,我可以添加一个自定义Windows窗体控件该项目的WPF应用程序视图,它使空的自定义控制,但我无法弄清楚如何添加它。理想情况下,我想知道如何从我的窗户编译采取.dll文件构成的用户控制和它粘成WPF应用程序,或导入用户控件到WPF应用程序。
As a short term solution I'm trying to jam a windows form 'usercontrol' into a WPF application. I see in the WPF application view that I can add a 'custom windows form control' to the project and it makes an empty custom control, but I can't figure out how to add it. Ideally I'd like to know how to take the .dll from my compiled windows forms user control and stick it into the WPF app, or import the user control into the WPF application.
谢谢,
山姆
推荐答案
您真的不能把它添加作为对照像你工具箱可以为Windows窗体应用程序。你应该做的,而不是为主机WPF应用程序内的用户控件。
You can't really add it as a control to the toolbox like you could for a Windows Forms Application. What you should do instead is "host" the user control inside of the WPF application.
的。
下面是如何使用一个蒙面的文本框的例子(你可以轻松地修改使用您的自定义控件):
Here's an example of how to use a masked text box (which you can easily modify to use your custom control):
<Window x:Class="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;assembly=System.Windows.Forms"
Title="HostingWfInWpf">
<Grid>
<WindowsFormsHost>
<wf:MaskedTextBox x:Name="mtbDate" Mask="00/00/0000"/>
</WindowsFormsHost>
</Grid>
</Window>
这篇关于如何把一个WPF应用程序自定义Windows窗体控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!