wpf怎么使用WindowsFormsHost(使用WinForms中的控件)

使用方法:
  1、首先,我们需要向项目中的引用(reference)中添加两个动态库dll,一个是.NET库中的System.Windows.Forms,另外一个是WindowsFormsIntegration;
  2、添加完两个动态dll以后,就可以在控件库中找到WindowsFormsHost这个控件;
  3、将这个控件放入窗体,放置完以后在xmal代码中会自动生成相应代码:
  <Grid>
  <WindowsFormsHost Height="100" HorizontalAlignment="Left" Margin="36,29,0,0" Name="windowsFormsHost1" VerticalAlignment="Top" Width="200" />
  </Grid>
  4、然后,需要在xmal的开始处添加两行代码 :
  xmlns:WinFormHost="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
  xmlns:WinFormControls="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
  5、这样就可以在WindowsFormsHost下放置需要的Windows Form控件了。
  <WindowsFormsHost Height="196" HorizontalAlignment="Left" Margin="104,65,0,0" Name="windowsFormsHost1" VerticalAlignment="Top" Width="286" >
  <WinFormControls:Button Text="WinformButton" Width="150"/>
  </WindowsFormsHost>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值