Skip to main content
 首页 » 编程设计

c#之在 System.Windows.UIElement 中包装来自 System.Windows.Forms 的控件

2024年02月24日17sharpest

是否可以将旧的 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>