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

标签 c# wpf winforms

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

相关文章:

c# - 带有可选参数的 web api 路由

c# - iOS 8 中的 IsolatedStorage 异常

c# - 如何调试DLL里面的代码

c# - Windows xp 上的 DrawToBitmap

c# - 输入字符串的格式不正确

c# - linq 语法选项

c# - 第 n 个素数问题,需要加快速度

WPF 扩展工具包向导验证

c# - 在现有模型对象之上实例化 ViewModels 和 Views

c# - 初始加载后取消选择列表框中的所有项目