是否可以将旧的 System.Windows.Forms 控件包装在 System.Windows.UIElement 中?我知道 Browser Control以某种方式包装,基础来自 System.Windows.Forms。
如果这是可能的,实现会造成任何后果吗?
最佳答案
您可以在 WPF 窗体中承载 Windows 窗体控件。只需将它包装在 WindowsFormsHost 元素中。这显示了如何在 WPF 窗口中托管 Windows 窗体屏蔽测试框。
<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>
关于c# - 在 System.Windows.UIElement 中包装来自 System.Windows.Forms 的控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1754661/