WPF上使用winform控件

本文介绍如何在WPF项目中使用WinForm的PictureBox控件,并指导读者如何加载WindowsFormsIntegration和System.Windows.Forms依赖,以及在XAML中正确配置控件。

前言

由于最近在写视频播放界面,sdk文档上的方法中提到需要获取到控件的手柄,但wpf里this.Handle代表的是整个窗体的手柄,sdk的demo是使用winform的控件PictureBox,但在wpf里没有这个控件,在网上查找资料时发现wpf里可以使用winform的控件。

一:加载winform的依赖

1.WindowsFormsIntegration.dll,System.Windows.Forms.dll。
在这里插入图片描述

二:在xmal里加入需要引入的xml和控件

1.在xmal里加入依赖
在这里插入图片描述

xmlns:wfh="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:wfc="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"

2.加入控件

<WindowsFormsHost x:Name="form4" Grid.Row="2" Grid.Column="2" Background="Black" >
                    <wf:PictureBox x:Name="userCtrl4" MouseDoubleClick="BWinForms_DocumentTitleChanged3"/>
</WindowsFormsHost>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值