如何在WPF中嵌入Winform控件
1个回答
展开全部
当时把WPF的控件canvas的handle传给C++的项目去刷新图像的时候发现最后刷新的是整个WPF页面而不是控件所在的区域,还不知道有什么办法可以解决。
不过可以在WPF中嵌入WINFORM的图像控件PictureBox去做刷新。
嵌入方法:
1.在项目的References中加入WindowsFormsIntegration.dll和System.Windows.Form.dll
2.在页面的WPF中加入
[csharp] view plain copy
xmlns:wfi ="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:wf ="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
比如
[csharp] view plain copy
x:Class="WpfApplication1.MainWindow"
xmlns:wfi ="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:wf ="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="800" Width="1280" MouseMove="Window_MouseMove" MouseLeftButtonUp="Window_MouseLeftButtonUp" MouseDown="Window_MouseDown" MouseLeftButtonDown="Window_MouseLeftButtonDown">
然后我在Gridzhong 放下图像控件
[csharp] view plain copy
<Grid HorizontalAlignment="Left" Height="482" Margin="6,6,0,0" VerticalAlignment="Top" Width="737">
<wfi:WindowsFormsHost>
<wf:PictureBox x:Name="Cv_Main" Margin="0,0,0,0"></wf:PictureBox>
</wfi:WindowsFormsHost>
</Grid>
大功告成
不过可以在WPF中嵌入WINFORM的图像控件PictureBox去做刷新。
嵌入方法:
1.在项目的References中加入WindowsFormsIntegration.dll和System.Windows.Form.dll
2.在页面的WPF中加入
[csharp] view plain copy
xmlns:wfi ="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:wf ="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
比如
[csharp] view plain copy
x:Class="WpfApplication1.MainWindow"
xmlns:wfi ="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:wf ="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="800" Width="1280" MouseMove="Window_MouseMove" MouseLeftButtonUp="Window_MouseLeftButtonUp" MouseDown="Window_MouseDown" MouseLeftButtonDown="Window_MouseLeftButtonDown">
然后我在Gridzhong 放下图像控件
[csharp] view plain copy
<Grid HorizontalAlignment="Left" Height="482" Margin="6,6,0,0" VerticalAlignment="Top" Width="737">
<wfi:WindowsFormsHost>
<wf:PictureBox x:Name="Cv_Main" Margin="0,0,0,0"></wf:PictureBox>
</wfi:WindowsFormsHost>
</Grid>
大功告成
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询