Shi*_*zam 5 c# wpf user-controls
作为一个短期解决方案,我试图将Windows表单'usercontrol'阻塞到WPF应用程序中.我在WPF应用程序视图中看到我可以向项目添加一个"自定义窗体控件",它会生成一个空的自定义控件,但我无法弄清楚如何添加它.理想情况下,我想知道如何从我编译的Windows窗体用户控件中获取.dll并将其粘贴到WPF应用程序中,或将用户控件导入WPF应用程序.
谢谢,山姆
您无法像在Windows窗体应用程序中那样将其作为控件添加到工具箱中.你应该做的是"托管"WPF应用程序内部的用户控件.
以下是如何使用蒙版文本框(您可以轻松修改以使用自定义控件)的示例:
<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>
Run Code Online (Sandbox Code Playgroud)